文件
hyb-oa/client/src/api/errorMessages.ts
T

330 行
11 KiB
TypeScript

import { formatInvoiceOcrFieldLabels } from "../lib/invoiceOcr";
function readStringList(value: unknown): string[] {
if (!Array.isArray(value)) {
return [];
}
return value
.map((item) => (typeof item === "string" ? item.trim() : ""))
.filter((item) => item.length > 0);
}
const FEATURE_FLAG_DISABLED_MESSAGES: Record<string, string> = {
portal_home_v1_disabled: "Portal 首页当前未启用,请联系管理员检查环境开关与功能开关配置。",
announcements_v1_disabled: "公告模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
presence_board_v1_disabled: "团队状态模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
attendance_v1_disabled: "考勤模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
weekly_report_v1_disabled: "周报模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
employee_lifecycle_v1_disabled: "人员生命周期模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
todo_board_v1_disabled: "待办模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
project_domain_v1_disabled: "项目模块当前未启用,请联系管理员检查环境开关与功能开关配置。",
project_linking_v1_disabled: "项目关联功能当前未启用,请联系管理员检查环境开关与功能开关配置。",
project_communication_log_v1_disabled: "项目沟通回填当前未启用,请联系管理员检查环境开关与功能开关配置。",
project_closure_checklist_v1_disabled: "项目收口清单当前未启用,请联系管理员检查环境开关与功能开关配置。",
confidential_doc_refs_v1_disabled: "涉密资料引用当前未启用,请联系管理员检查环境开关与功能开关配置。",
};
function resolveFeatureFlagDisabledMessage(value: unknown): string | null {
if (typeof value !== "string" || !value.endsWith("_disabled")) {
return null;
}
return (
FEATURE_FLAG_DISABLED_MESSAGES[value] ??
"当前功能未启用,请联系管理员检查环境开关与功能开关配置。"
);
}
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 "票据识别重试次数已达上限,请稍后人工处理。";
}
if (code === "VALID_007") {
return "票据识别重试过于频繁,请稍后再试。";
}
if (code === "VALID_001") {
const passwordErrors = readStringList(details?.password);
if (passwordErrors.length) {
return `新密码不符合要求:${passwordErrors.join(";")}。`;
}
const featureFlagMessage = resolveFeatureFlagDisabledMessage(details?.featureFlag);
if (featureFlagMessage) {
return featureFlagMessage;
}
if (details?.["x-device-fingerprint"] === "missing") {
return "当前设备校验信息缺失,请刷新页面后重试。";
}
if (details?.payment === "already_paid_conflict") {
return "该报销单已支付且付款信息冲突,请刷新后确认。";
}
if (details?.status === "invalid_pay_status") {
return "当前状态不允许执行付款。";
}
if (details?.review === "maker_checker_conflict") {
return "复核人与批次创建人不能是同一人。";
}
if (details?.review === "second_reviewer_conflict") {
return "二次复核人不能与首个复核人相同。";
}
if (details?.review === "high_risk_second_review_required") {
return "当前为高风险付款批次,完成二次复核后才能执行。";
}
if (details?.review === "batch_review_required") {
return "当前批次尚未完成复核,不能执行。";
}
if (details?.review === "batch_not_reviewable") {
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?.invoices === "bound_invoice_required") {
return "提交前请先绑定至少 1 张发票。";
}
if (details?.invoice === "not_bound") {
return "该票据未绑定报销单,无法解绑。";
}
if (details?.reimbursement === "invalid_status_for_unbind") {
return "仅草稿/驳回状态的报销单允许解绑票据。";
}
if (details?.ocr === "disabled") {
return "当前环境未开启票据识别,请联系管理员处理。";
}
if (details?.ocr === "missing_required_fields") {
const labels = formatInvoiceOcrFieldLabels(readStringList(details?.missingFields));
if (labels.length) {
return `票据仍缺少关键字段:${labels.join("、")},补齐后才能标记为可用。`;
}
return "票据仍缺少关键字段,补齐后才能标记为可用。";
}
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 || "请求失败,请稍后重试。";
}