fix(web): 后端不可用统一用 BackendDownNotice 替代 404/手搓提示

This commit is contained in:
Yaojia Wang
2026-06-29 16:52:43 +02:00
parent f8cabc92e6
commit 47eb42f274
6 changed files with 52 additions and 26 deletions

View File

@@ -1,7 +1,9 @@
import { notFound } from "next/navigation";
import { BackendDownNotice } from "@/components/BackendDownNotice";
import { ForeshadowBoard } from "@/components/foreshadow/ForeshadowBoard";
import { fetchForeshadow, fetchProject } from "@/lib/api/server";
import type { ForeshadowView, ProjectResponse } from "@/lib/api/types";
interface PageProps {
params: Promise<{ id: string }>;
@@ -11,13 +13,30 @@ interface PageProps {
// ForeshadowBoardClient按 status 分四泳道并承载登记/状态变更交互。
export default async function ForeshadowPage({ params }: PageProps) {
const { id } = await params;
// 仅当项目确实不存在404才判 notFound后端不可用等其它失败降级为「后端不可达」提示
// 不把整页变成「找不到页面」。
let project: ProjectResponse;
try {
const project = await fetchProject(id);
const board = await fetchForeshadow(id);
return (
<ForeshadowBoard project={project} initialItems={board.foreshadow ?? []} />
);
} catch {
notFound();
project = await fetchProject(id);
} catch (err) {
if (isNotFoundError(err)) notFound();
return <BackendDownNotice className="m-6" />;
}
// 伏笔看板GET .../foreshadow。瞬时错误降级为空看板不阻塞进页。
let initialItems: ForeshadowView[] = [];
try {
const board = await fetchForeshadow(id);
initialItems = board.foreshadow ?? [];
} catch {
initialItems = [];
}
return <ForeshadowBoard project={project} initialItems={initialItems} />;
}
// fetchProject 抛错信息形如「请求失败 404: ...」;据此区分「项目不存在」与「后端不可用」。
function isNotFoundError(err: unknown): boolean {
return err instanceof Error && err.message.includes("请求失败 404");
}