feat(app): 按错误码展示中英印尼文案

This commit is contained in:
Zhou Weidong committed 2026-10-23 13:05:29 +08:00
1 parent 0ef0d46919
commit b1e95b370c
10 files changed
+331 -6

No files matched your search

+27 -4
View File
@@ -2,14 +2,37 @@
import '../../l10n/app_localizations.dart';
const int _serverErrorCode = 500;
/// 用户端不展示内部故障文案。500 与空提示改成可理解的说明,业务提示原样保留。
/// 按后端 `ErrorCode` 取当前语言文案。未收录的业务码回退服务端 message。
String userFacingApiMessage(AppLocalizations l10n, int code, String message) {
if (code >= _serverErrorCode || message.isEmpty) return l10n.authServerError;
final localized = _apiMessage(l10n, code);
if (localized != null) return localized;
if (message.isEmpty) return l10n.authServerError;
return message;
}
/// 已定义错误码。500 用服务繁忙,不展示「系统异常」。
String? _apiMessage(AppLocalizations l10n, int code) {
return switch (code) {
400 => l10n.apiErrorBadRequest,
401 => l10n.apiErrorUnauthorized,
403 => l10n.apiErrorForbidden,
404 => l10n.apiErrorNotFound,
429 => l10n.apiErrorTooManyRequests,
500 => l10n.authServerError,
100000 => l10n.apiErrorLoginFailed,
100001 => l10n.apiErrorAccountDisabled,
100002 => l10n.apiErrorCoinNotEnough,
100003 => l10n.apiErrorEpisodeUnavailable,
100004 => l10n.apiErrorEpisodeUnlocked,
100005 => l10n.apiErrorOrderInvalid,
100006 => l10n.apiErrorVipExpired,
200001 => l10n.apiErrorDataExists,
200002 => l10n.apiErrorDataNotFound,
200003 => l10n.apiErrorNotAllowed,
_ => null,
};
}
/// logic 里的错误在两种情况下是"哨兵值":本地网络异常(读不到后端提示语)与
/// 我们自己包装的失败。这里统一翻译成当前语言的文案;服务端给的中文提示原样展示。
String errorText(AppLocalizations l10n, String? code, String fallback) {