import { ApiClientError } from "@geo/http-client"; const errorMessageMap: Record = { invalid_credentials: "邮箱或密码错误", no_tenant: "当前账号未关联租户", not_authenticated: "请先登录", invalid_access_token: "登录状态已失效", invalid_refresh_token: "刷新令牌已失效", refresh_session_expired: "登录已过期,请重新登录", refresh_token_mismatch: "刷新令牌校验失败,请重新登录", token_revoked: "当前会话已经退出", tenant_scope_missing: "租户上下文缺失", query_failed: "数据读取失败", quota_insufficient: "生成额度不足", trial_plan_expired: "免费试用已到期,请联系管理员开通", subscription_required: "当前租户尚未开通有效套餐,请联系管理员", subscription_inactive: "当前租户套餐已失效,请联系管理员", llm_unavailable: "生成服务不可用", analyze_context_required: "请先填写品牌或模板上下文信息", title_context_required: "请先确认品牌、关键词或竞品信息", outline_context_required: "请先确认标题和文章结构后再生成大纲", analyze_queue_unavailable: "品牌分析任务较多,请稍后重试", title_queue_unavailable: "标题生成任务较多,请稍后重试", outline_queue_unavailable: "大纲生成任务较多,请稍后重试", analyze_task_not_found: "品牌分析任务不存在或已失效", title_task_not_found: "标题生成任务不存在或已失效", outline_task_not_found: "文章大纲任务不存在或已失效", article_generating: "文章仍在生成中", article_not_editable: "只有已完成文章才可编辑", article_lookup_failed: "文章状态读取失败", draft_not_editable: "只有草稿或生成失败的文章才可继续在向导中编辑", article_title_required: "请输入文章标题", invalid_image: "请选择图片文件", image_upload_too_large: "图片不能超过 10MB", image_upload_type_not_supported: "仅支持 PNG、JPG、JPEG、GIF、WebP、BMP、SVG、AVIF 图片", image_canvas_context_unavailable: "当前浏览器暂不支持该图片处理能力,请更换浏览器后重试", image_load_failed: "图片解析失败,请重新选择图片", article_image_too_large: "图片不能超过 10MB", article_image_type_not_supported: "仅支持 PNG、JPG、GIF、WebP 图片", article_image_upload_failed: "图片上传失败", article_image_url_unavailable: "图片地址生成失败", object_storage_unavailable: "对象存储未配置或当前不可用", invalid_payload: "请求参数不合法", update_failed: "保存文章失败", brand_exists: "品牌名称已存在", brand_limit_reached: "品牌公司数量已达当前套餐上限", keyword_exists: "关键词已存在", keyword_limit_reached: "关键词数量已达当前套餐上限", question_limit_reached: "当前关键词下的问题数量已达上限", brand_not_found: "品牌不存在或已删除", keyword_not_found: "关键词不存在或已删除", publish_cover_required: "已选择百家号,请先上传封面图", publisher_plugin_timeout: "浏览器插件响应超时,请刷新当前页面后重试", publisher_plugin_empty_response: "浏览器插件未返回数据,请刷新当前页面后重试", publisher_plugin_invalid_response: "浏览器插件返回了无效数据,请刷新当前页面后重试", publisher_plugin_unknown_error: "浏览器插件调用失败,请稍后重试", monitoring_plugin_timeout: "监测插件响应超时,请稍后重试", monitoring_plugin_invalid_response: "监测插件返回了无效数据,请稍后重试", monitoring_plugin_unknown_error: "监测插件调用失败,请稍后重试", monitoring_plugin_required: "请先安装并打开浏览器插件", monitoring_plugin_register_required: "浏览器插件正在初始化,请稍后重试", installation_offline: "监测插件离线,请打开浏览器插件后重试", network_error: "网络连接失败,请稍后重试", unknown_error: "发生未知错误", }; export function formatError(error: unknown): string { if (error instanceof ApiClientError) { const message = errorMessageMap[error.message] ?? error.message.replaceAll("_", " "); return error.detail ? `${message}: ${error.detail}` : message; } if (error instanceof Error) { return errorMessageMap[error.message] ?? error.message; } return "发生未知错误"; }