Files
geo/apps/admin-web/src/lib/errors.ts
T

86 lines
4.8 KiB
TypeScript
Raw Normal View History

import { ApiClientError } from "@geo/http-client";
const errorMessageMap: Record<string, string> = {
invalid_credentials: "邮箱或密码错误",
login_rate_limited: "登录请求过于频繁",
login_locked: "登录已被临时保护",
login_in_progress: "登录请求正在处理中",
login_guard_unavailable: "登录保护暂时不可用",
no_tenant: "当前账号未关联租户",
not_authenticated: "请先登录",
missing_bearer_token: "请先登录",
invalid_access_token: "登录状态已失效",
user_disabled: "用户被停用,请联系客服",
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: "请选择图片文件",
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: "图片解析失败,请重新选择图片",
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: "保存文章失败",
2026-04-16 21:01:40 +08:00
brand_exists: "品牌名称已存在",
brand_limit_reached: "品牌公司数量已达当前套餐上限",
keyword_exists: "关键词已存在",
keyword_limit_reached: "关键词数量已达当前套餐上限",
question_limit_reached: "当前关键词下的问题数量已达上限",
knowledge_text_name_too_long: "文本名称不能超过 20 个字",
2026-04-16 21:01:40 +08:00
brand_not_found: "品牌不存在或已删除",
keyword_not_found: "关键词不存在或已删除",
publish_cover_required: "当前选择的平台要求上传封面图,请先上传封面图",
desktop_account_client_missing: "所选账号还没有绑定桌面客户端,暂时无法发布",
desktop_account_not_found: "所选桌面账号不存在,请刷新后重试",
desktop_client_offline: "当前登录账号的桌面客户端未在线,请先打开 desktop-client",
desktop_publish_job_store_unavailable: "发布队列暂时不可用,请稍后重试",
desktop_media_api_removed: "旧版媒体接口已下线,请刷新页面后重试",
publisher_plugin_timeout: "浏览器插件响应超时,请刷新当前页面后重试",
publisher_plugin_empty_response: "浏览器插件未返回数据,请刷新当前页面后重试",
publisher_plugin_invalid_response: "浏览器插件返回了无效数据,请刷新当前页面后重试",
publisher_plugin_unknown_error: "浏览器插件调用失败,请稍后重试",
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 "发生未知错误";
}