修复 API 500 响应泄露内部错误细节

This commit is contained in:
2026-03-03 12:11:02 +08:00
parent 486193c823
commit 5a6d457a87
3 changed files with 11 additions and 4 deletions
+4 -2
View File
@@ -60,9 +60,11 @@ export function apiHandler(handler: RouteHandler): RouteHandler {
{ status: 409 },
);
}
const detail = e instanceof Error ? `${e.name}: ${e.message}` : String(e);
console.error(`[API ${req.method} ${req.nextUrl.pathname}]`, e);
return NextResponse.json({ error: `操作失败 [${detail}]` }, { status: 500 });
return NextResponse.json(
{ error: "操作失败,请稍后重试" },
{ status: 500 },
);
}
};
}