feat(player, i18n): add error code mappings and back to main site button
1. 新增8001-8005业务错误码的国际化翻译与映射 2. 增加返回主站按钮,根据环境变量显示 3. 重构错误码匹配逻辑,复用常量对象
This commit is contained in:
@@ -17,7 +17,7 @@ import { useTranslation } from "react-i18next";
|
||||
|
||||
import { getPlayerMe, getPlayerPing } from "@/api/player";
|
||||
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 { usePlayerSessionStore } from "@/stores/player-session-store";
|
||||
import { LotteryApiBizError } from "@/types/api/errors";
|
||||
@@ -25,6 +25,17 @@ import { LotteryApiBizError } from "@/types/api/errors";
|
||||
const RETRY_ATTEMPTS = 3;
|
||||
const RETRY_DELAY_MS = 2000;
|
||||
|
||||
const MAIN_SITE_URL = process.env.NEXT_PUBLIC_MAIN_SITE_URL?.trim() ?? "";
|
||||
|
||||
/** `/api/player/me` 等业务信封业务码 — 玩家 SSO 段 8001–8005(与后端 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 EntryStepStatus = "pending" | "in-progress" | "done" | "error";
|
||||
@@ -160,12 +171,7 @@ export function EntryGate() {
|
||||
|
||||
const details: FailureRow[] = [];
|
||||
if (typeof err.code === "number") {
|
||||
const keyByCode: Partial<Record<number, string>> = {
|
||||
401: "errors.http401",
|
||||
403: "errors.http403",
|
||||
404: "errors.http404",
|
||||
};
|
||||
const dk = keyByCode[err.code];
|
||||
const dk = PLAYER_BIZ_DETAIL[err.code];
|
||||
details.push({
|
||||
code: String(err.code),
|
||||
...(dk ? { detailKey: dk } : {}),
|
||||
@@ -373,15 +379,27 @@ export function EntryGate() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<Button
|
||||
onClick={handleRetry}
|
||||
className="w-full gap-2 bg-red-600 text-white hover:bg-red-700"
|
||||
size="lg"
|
||||
type="button"
|
||||
>
|
||||
<Loader2 className="size-4" aria-hidden />
|
||||
{t("failure.reenter")}
|
||||
</Button>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Button
|
||||
onClick={handleRetry}
|
||||
className="w-full gap-2 bg-red-600 text-white hover:bg-red-700"
|
||||
size="lg"
|
||||
type="button"
|
||||
>
|
||||
<Loader2 className="size-4" aria-hidden />
|
||||
{t("failure.reenter")}
|
||||
</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>
|
||||
) : null}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user