2026-04-01 00:58:42 +08:00
|
|
|
import { ApiClientError } from "@geo/http-client";
|
|
|
|
|
|
|
|
|
|
const errorMessageMap: Record<string, string> = {
|
|
|
|
|
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: "生成额度不足",
|
|
|
|
|
llm_unavailable: "生成服务不可用",
|
2026-04-02 00:31:28 +08:00
|
|
|
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: "只有已完成文章才可编辑",
|
2026-04-05 22:10:05 +08:00
|
|
|
article_lookup_failed: "文章状态读取失败",
|
2026-04-02 00:31:28 +08:00
|
|
|
draft_not_editable: "只有草稿或生成失败的文章才可继续在向导中编辑",
|
|
|
|
|
article_title_required: "请输入文章标题",
|
2026-04-05 22:10:05 +08:00
|
|
|
invalid_image: "请选择图片文件",
|
2026-04-16 20:40:41 +08:00
|
|
|
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: "图片解析失败,请重新选择图片",
|
2026-04-05 22:10:05 +08:00
|
|
|
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: "对象存储未配置或当前不可用",
|
2026-04-02 00:31:28 +08:00
|
|
|
invalid_payload: "请求参数不合法",
|
|
|
|
|
update_failed: "保存文章失败",
|
2026-04-07 09:19:03 +08:00
|
|
|
publish_cover_required: "已选择百家号,请先上传封面图",
|
2026-04-03 17:48:30 +08:00
|
|
|
publisher_plugin_timeout: "浏览器插件响应超时,请刷新当前页面后重试",
|
|
|
|
|
publisher_plugin_empty_response: "浏览器插件未返回数据,请刷新当前页面后重试",
|
|
|
|
|
publisher_plugin_invalid_response: "浏览器插件返回了无效数据,请刷新当前页面后重试",
|
|
|
|
|
publisher_plugin_unknown_error: "浏览器插件调用失败,请稍后重试",
|
2026-04-12 09:56:18 +08:00
|
|
|
monitoring_plugin_timeout: "监测插件响应超时,请稍后重试",
|
|
|
|
|
monitoring_plugin_invalid_response: "监测插件返回了无效数据,请稍后重试",
|
|
|
|
|
monitoring_plugin_unknown_error: "监测插件调用失败,请稍后重试",
|
|
|
|
|
monitoring_plugin_required: "请先安装并打开浏览器插件",
|
|
|
|
|
monitoring_plugin_register_required: "浏览器插件正在初始化,请稍后重试",
|
|
|
|
|
installation_offline: "监测插件离线,请打开浏览器插件后重试",
|
2026-04-01 00:58:42 +08:00
|
|
|
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) {
|
2026-04-03 17:48:30 +08:00
|
|
|
return errorMessageMap[error.message] ?? error.message;
|
2026-04-01 00:58:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "发生未知错误";
|
|
|
|
|
}
|