refactor: 提取 buildNavUrl 工具函数,统一 room API 错误处理

- 将 MatchResult.tsx 和 profile/page.tsx 中重复的导航 URL 构建逻辑提取到 src/lib/navigation.ts
- 7 个 room API 路由从 return NextResponse.json({ error }, { status }) 统一改为 throw ApiError,由 apiHandler 统一捕获
This commit is contained in:
2026-02-26 19:31:00 +08:00
parent c9e20d4c95
commit 9641acbcbd
10 changed files with 21 additions and 58 deletions
+2 -7
View File
@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { atomicUpdateRoom } from "@/lib/store";
import { notify } from "@/lib/roomEvents";
import { apiHandler } from "@/lib/api";
import { apiHandler, ApiError } from "@/lib/api";
export const POST = apiHandler(async (req, { params }) => {
const { id } = await params;
@@ -27,12 +27,7 @@ export const POST = apiHandler(async (req, { params }) => {
return data;
});
if (!updated) {
return NextResponse.json(
{ error: "房间不存在或已过期" },
{ status: 404 },
);
}
if (!updated) throw new ApiError("房间不存在或已过期", 404);
notify(id);