246 行
7.1 KiB
TypeScript
246 行
7.1 KiB
TypeScript
export function mapApiErrorMessage(
|
|
code: string,
|
|
details?: Record<string, unknown>,
|
|
fallbackMessage?: string,
|
|
) {
|
|
if (code === "AUTH_001") {
|
|
return "账号或密码错误,请检查后重试。";
|
|
}
|
|
|
|
if (code === "AUTH_002") {
|
|
const lockedUntil = typeof details?.lockedUntil === "string" ? details.lockedUntil : null;
|
|
if (lockedUntil) {
|
|
const until = new Date(lockedUntil);
|
|
if (!Number.isNaN(until.getTime())) {
|
|
return `账号已锁定至 ${until.toLocaleString()},请稍后重试。`;
|
|
}
|
|
}
|
|
return "账号已锁定,请稍后重试。";
|
|
}
|
|
|
|
if (code === "AUTH_003") {
|
|
return "账号已离职/禁用,请联系管理员。";
|
|
}
|
|
|
|
if (code === "AUTH_004") {
|
|
return "登录状态失效,请重新登录。";
|
|
}
|
|
|
|
if (code === "AUTH_005") {
|
|
return "登录状态已失效,请重新登录。";
|
|
}
|
|
|
|
if (code === "PERM_001") {
|
|
return "当前账号无权限执行该操作。";
|
|
}
|
|
|
|
if (code === "PERM_002") {
|
|
return "你不是当前任务处理人,无法执行该操作。";
|
|
}
|
|
|
|
if (code === "SYS_404") {
|
|
return "目标数据不存在或已被删除。";
|
|
}
|
|
|
|
if (code === "SYS_001") {
|
|
return "服务暂不可用,请稍后重试或联系管理员。";
|
|
}
|
|
|
|
if (code === "SYS_429") {
|
|
return "请求过于频繁,请稍后重试。";
|
|
}
|
|
|
|
if (code === "VALID_002") {
|
|
return "输入内容长度不足,请补充后再提交。";
|
|
}
|
|
|
|
if (code === "VALID_003") {
|
|
return "票据疑似重复,请核对后再上传或联系财务处理。";
|
|
}
|
|
|
|
if (code === "VALID_004") {
|
|
return "原始单据已审批通过/付款,当前操作不允许。";
|
|
}
|
|
|
|
if (code === "VALID_005") {
|
|
return "票据已绑定报销单,无需重复绑定。";
|
|
}
|
|
|
|
if (code === "VALID_006") {
|
|
return "OCR 重试次数已达上限,请稍后人工处理。";
|
|
}
|
|
|
|
if (code === "VALID_007") {
|
|
return "OCR 重试过于频繁,请稍后再试。";
|
|
}
|
|
|
|
if (code === "VALID_001") {
|
|
if (details?.payment === "already_paid_conflict") {
|
|
return "该报销单已支付且付款信息冲突,请刷新后确认。";
|
|
}
|
|
|
|
if (details?.status === "invalid_pay_status") {
|
|
return "当前状态不允许执行付款。";
|
|
}
|
|
|
|
if (details?.transfer === "chain_limit_exceeded") {
|
|
return "当前任务转审次数已达上限。";
|
|
}
|
|
|
|
if (details?.transfer === "same_assignee_not_allowed") {
|
|
return "不能将任务转审给自己。";
|
|
}
|
|
|
|
if (details?.toApproverId === "target_not_approver") {
|
|
return "目标人员不具备审批权限。";
|
|
}
|
|
|
|
if (details?.toApproverId === "invalid_target") {
|
|
return "目标审批人不存在或已停用。";
|
|
}
|
|
|
|
if (details?.task === "already_processed") {
|
|
return "该任务已被处理,请刷新列表。";
|
|
}
|
|
|
|
if (details?.invoice === "not_bound") {
|
|
return "该票据未绑定报销单,无法解绑。";
|
|
}
|
|
|
|
if (details?.reimbursement === "invalid_status_for_unbind") {
|
|
return "仅草稿/驳回状态的报销单允许解绑票据。";
|
|
}
|
|
|
|
if (details?.ocr === "disabled") {
|
|
return "当前环境未开启 OCR,请联系管理员或切换到 mock/tencent。";
|
|
}
|
|
|
|
|
|
if (details?.verification === "disabled") {
|
|
return "当前环境未开启发票验真。";
|
|
}
|
|
if (details?.code === "duplicate") {
|
|
return "编码已存在,请更换后重试。";
|
|
}
|
|
|
|
if (details?.legalEntityId === "not_found") {
|
|
return "所选法体不存在。";
|
|
}
|
|
|
|
if (details?.legalEntityId === "archived") {
|
|
return "所选法体已归档,无法继续使用。";
|
|
}
|
|
|
|
if (details?.ownerEmployeeId === "not_found") {
|
|
return "负责人不存在或已停用。";
|
|
}
|
|
|
|
if (details?.parentId === "not_found") {
|
|
return "上级成本中心不存在。";
|
|
}
|
|
|
|
if (details?.parentId === "archived") {
|
|
return "上级成本中心已归档,无法继续使用。";
|
|
}
|
|
|
|
if (details?.parentId === "self_not_allowed") {
|
|
return "上级成本中心不能选择自身。";
|
|
}
|
|
|
|
if (details?.parentId === "cycle_not_allowed") {
|
|
return "上级成本中心不能形成循环层级。";
|
|
}
|
|
|
|
if (details?.parentId === "cross_legal_entity_not_allowed") {
|
|
return "上级成本中心必须与当前法体一致。";
|
|
}
|
|
|
|
if (details?.legalEntity === "has_cost_centers") {
|
|
return "当前法体下仍存在未归档的成本中心,无法归档。";
|
|
}
|
|
|
|
if (details?.costCenter === "has_children") {
|
|
return "当前成本中心存在下级节点,无法归档。";
|
|
}
|
|
|
|
if (details?.holidayCalendar === "bound_as_default") {
|
|
return `当前日历仍被法体 ${details?.legalEntityCode ?? ""} 作为默认日历引用,无法归档。`;
|
|
}
|
|
|
|
if (details?.date === "duplicate") {
|
|
return "同一日历内不允许存在重复日期。";
|
|
}
|
|
|
|
|
|
if (details?.verification === "already_pending") {
|
|
return "已有验真任务正在处理中,请稍后查看结果。";
|
|
}
|
|
|
|
if (details?.verification === "too_frequent") {
|
|
return "验真触发过于频繁,请稍后重试。";
|
|
}
|
|
|
|
if (details?.verification === "attempts_exceeded") {
|
|
return "验真重试次数已达上限,请联系财务人工核验。";
|
|
}
|
|
|
|
if (details?.budget === "exceeded_block_mode") {
|
|
return "当前报销金额超出预算,系统已阻断提交。";
|
|
}
|
|
|
|
if (details?.leave === "conflict_range") {
|
|
return "当前时间段与已有请假记录冲突,请调整后再提交。";
|
|
}
|
|
|
|
if (details?.leave === "insufficient_balance") {
|
|
return "当前假种可用额度不足,无法提交。";
|
|
}
|
|
|
|
if (details?.leave === "invalid_range") {
|
|
return "请假开始/结束日期与半天时段不合法。";
|
|
}
|
|
|
|
if (details?.leave === "non_working_range") {
|
|
return "所选时间段均为非工作日,无需请假。";
|
|
}
|
|
|
|
if (details?.leave === "missing_reserve_ledger") {
|
|
return "请假冻结账本状态异常,请联系管理员处理。";
|
|
}
|
|
|
|
if (details?.file === "required") {
|
|
return "当前假种要求上传附件后才能提交。";
|
|
}
|
|
|
|
if (details?.file === "unsupported_mime_type") {
|
|
return "附件类型不被当前假种接受,请重新选择。";
|
|
}
|
|
|
|
if (details?.withdraw === "no_pending_instance") {
|
|
return "当前请假单不存在可撤回的审批实例。";
|
|
}
|
|
|
|
if (details?.withdraw === "already_processed_by_approver") {
|
|
return "审批人已处理该请假单,当前不能撤回。";
|
|
}
|
|
|
|
if (details?.leaveTypeId === "missing_active_policy") {
|
|
return "当前假种未配置可用策略,请联系 HR。";
|
|
}
|
|
|
|
if (details?.integration === "erp_sync_disabled") {
|
|
return "ERP 同步功能未开启。";
|
|
}
|
|
|
|
if (details?.integration === "travel_sync_disabled") {
|
|
return "差旅同步功能未开启。";
|
|
}
|
|
|
|
if (details?.secret === "field_encryption_key_missing") {
|
|
return "当前环境未配置 FIELD_ENCRYPTION_KEY,无法保存或更新 Webhook Secret。";
|
|
}
|
|
}
|
|
|
|
return fallbackMessage || "请求失败,请稍后重试。";
|
|
}
|