feat(player, i18n): add error code mappings and back to main site button

1. 新增8001-8005业务错误码的国际化翻译与映射
2. 增加返回主站按钮,根据环境变量显示
3. 重构错误码匹配逻辑,复用常量对象
This commit is contained in:
2026-05-14 09:38:57 +08:00
parent 587a6ad66c
commit ece50ae3b5
4 changed files with 58 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ import { useTranslation } from "react-i18next";
import { getPlayerMe, getPlayerPing } from "@/api/player"; import { getPlayerMe, getPlayerPing } from "@/api/player";
import { LanguageSwitcher } from "@/components/language-switcher"; import { LanguageSwitcher } from "@/components/language-switcher";
import { Button } from "@/components/ui/button"; import { Button, buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { usePlayerSessionStore } from "@/stores/player-session-store"; import { usePlayerSessionStore } from "@/stores/player-session-store";
import { LotteryApiBizError } from "@/types/api/errors"; import { LotteryApiBizError } from "@/types/api/errors";
@@ -25,6 +25,17 @@ import { LotteryApiBizError } from "@/types/api/errors";
const RETRY_ATTEMPTS = 3; const RETRY_ATTEMPTS = 3;
const RETRY_DELAY_MS = 2000; const RETRY_DELAY_MS = 2000;
const MAIN_SITE_URL = process.env.NEXT_PUBLIC_MAIN_SITE_URL?.trim() ?? "";
/** `/api/player/me` 等业务信封业务码 — 玩家 SSO 段 80018005与后端 ErrorCode 一致) */
const PLAYER_BIZ_DETAIL: Partial<Record<number, string>> = {
8001: "errors.player8001",
8002: "errors.player8002",
8003: "errors.player8003",
8004: "errors.player8004",
8005: "errors.player8005",
};
type EntryStepId = "token" | "account" | "hall"; type EntryStepId = "token" | "account" | "hall";
type EntryStepStatus = "pending" | "in-progress" | "done" | "error"; type EntryStepStatus = "pending" | "in-progress" | "done" | "error";
@@ -160,12 +171,7 @@ export function EntryGate() {
const details: FailureRow[] = []; const details: FailureRow[] = [];
if (typeof err.code === "number") { if (typeof err.code === "number") {
const keyByCode: Partial<Record<number, string>> = { const dk = PLAYER_BIZ_DETAIL[err.code];
401: "errors.http401",
403: "errors.http403",
404: "errors.http404",
};
const dk = keyByCode[err.code];
details.push({ details.push({
code: String(err.code), code: String(err.code),
...(dk ? { detailKey: dk } : {}), ...(dk ? { detailKey: dk } : {}),
@@ -373,6 +379,7 @@ export function EntryGate() {
</div> </div>
) : null} ) : null}
<div className="flex flex-col gap-2">
<Button <Button
onClick={handleRetry} onClick={handleRetry}
className="w-full gap-2 bg-red-600 text-white hover:bg-red-700" className="w-full gap-2 bg-red-600 text-white hover:bg-red-700"
@@ -382,6 +389,17 @@ export function EntryGate() {
<Loader2 className="size-4" aria-hidden /> <Loader2 className="size-4" aria-hidden />
{t("failure.reenter")} {t("failure.reenter")}
</Button> </Button>
{MAIN_SITE_URL !== "" ? (
<a
href={MAIN_SITE_URL}
target="_top"
rel="noopener noreferrer"
className={cn(buttonVariants({ variant: "outline", size: "lg" }), "w-full")}
>
{t("failure.backToMainSite")}
</a>
) : null}
</div>
</div> </div>
) : null} ) : null}

View File

@@ -37,7 +37,8 @@
"check": "Check", "check": "Check",
"reason": "Reason" "reason": "Reason"
}, },
"reenter": "Re-enter" "reenter": "Re-enter",
"backToMainSite": "Back to main site"
}, },
"success": { "success": {
"title": "Authorization successful!", "title": "Authorization successful!",
@@ -60,6 +61,11 @@
"tryLater": "Please try again later", "tryLater": "Please try again later",
"http401": "Token is invalid or expired", "http401": "Token is invalid or expired",
"http403": "Account has been blocked", "http403": "Account has been blocked",
"http404": "Account not found in the system" "http404": "Account not found in the system",
"player8001": "Missing or invalid Authorization",
"player8002": "Token invalid, expired, malformed, or exceeding the allowed time window (e.g. >5 min)",
"player8003": "Player not registered (dev token only)",
"player8004": "SSO not configured on lottery server",
"player8005": "Account suspended or unavailable"
} }
} }

View File

@@ -37,7 +37,8 @@
"check": "जाँच", "check": "जाँच",
"reason": "कारण" "reason": "कारण"
}, },
"reenter": "पुन: प्रवेश" "reenter": "पुन: प्रवेश",
"backToMainSite": "मुख्य साइटमा फर्कनुहोस्"
}, },
"success": { "success": {
"title": "प्राधिकरण सफल!", "title": "प्राधिकरण सफल!",
@@ -60,6 +61,11 @@
"tryLater": "कृपया पछि प्रयास गर्नुहोस्", "tryLater": "कृपया पछि प्रयास गर्नुहोस्",
"http401": "टोकन अमान्य वा म्याद सकियो", "http401": "टोकन अमान्य वा म्याद सकियो",
"http403": "खाता रोकिएको छ", "http403": "खाता रोकिएको छ",
"http404": "प्रणालीमा खाता फेला परेन" "http404": "प्रणालीमा खाता फेला परेन",
"player8001": "अनुमति हेडर हराइरहेको छ वा अमान्य छ",
"player8002": "टोकन अमान्य, म्याद सकिएको, फिल्ड हराइएको वा समय सीमा मन नपर्ने",
"player8003": "खाता दर्ता छैन (विकास टोकन मात्र)",
"player8004": "लटरी सर्भरमा SSO कन्फिगर छैन",
"player8005": "खाता निलम्बन वा अनुपलब्ध"
} }
} }

View File

@@ -37,7 +37,8 @@
"check": "检查项", "check": "检查项",
"reason": "原因" "reason": "原因"
}, },
"reenter": "重新进入" "reenter": "重新进入",
"backToMainSite": "返回主站"
}, },
"success": { "success": {
"title": "授权成功!", "title": "授权成功!",
@@ -60,6 +61,11 @@
"tryLater": "请稍后再试", "tryLater": "请稍后再试",
"http401": "令牌无效或已过期", "http401": "令牌无效或已过期",
"http403": "账号已被封禁", "http403": "账号已被封禁",
"http404": "系统中未找到该账号" "http404": "系统中未找到该账号",
"player8001": "缺少或非法的授权凭证",
"player8002": "Token 无效、已过期或不符合时效(如有效窗超过 5 分钟/缺少必填字段)",
"player8003": "玩家未注册(仅开发 Token",
"player8004": "彩票服务端未配置 SSO",
"player8005": "账号已冻结或不可用"
} }
} }