- P1: server.ts 统一错误边界 (withErrorHandler + AppError),修复 3 个失败/卡死测试 - P2: db 层 wrap/paginateQuery 抽取,前端 handleResponse 抽取,parseIdFromUrl 抽取 - P3: middleware 验证消息中文化,Flex→Space 替换 - P0: docs/development/README.md 新增已知设计决策章节 - P3-11 setup 拆分已尝试回退(@testing-library/react preload 依赖无法拆分) - P3-13 config 层测试从本次变更移除
16 lines
615 B
TypeScript
16 lines
615 B
TypeScript
export async function handleResponse<T>(response: Response, extract: (data: unknown) => T): Promise<T> {
|
|
if (!response.ok) {
|
|
const body = (await response.json().catch(() => null)) as null | { error?: string };
|
|
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
|
}
|
|
const data: unknown = await response.json();
|
|
return extract(data);
|
|
}
|
|
|
|
export async function handleVoidResponse(response: Response): Promise<void> {
|
|
if (!response.ok) {
|
|
const body = (await response.json().catch(() => null)) as null | { error?: string };
|
|
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
|
}
|
|
}
|