Files
CamTalk/frontend/src/lib/errors.ts

16 lines
642 B
TypeScript
Raw Normal View History

// ============================================================
// 错误码 → 用户友好文案映射
// 来源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;
}