Files
CamTalk/frontend/src/lib/errors.ts
2026-06-14 20:40:05 +08:00

16 lines
642 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ============================================================
// 错误码 → 用户友好文案映射
// 来源docs/03-接口文档.md §五 错误码
// ============================================================
/** 将错误码转为用户友好文案(需要传入翻译函数) */
export function getErrorMessage(code: string, translate: (key: string) => string): string {
const key = `error.${code}`;
const translated = translate(key);
// 如果翻译函数返回 key 本身(未找到翻译),用 fallback
if (translated === key) {
return translate("error.unknown") + `: ${code}`;
}
return translated;
}