阶段四:完成 React Feature 化和异步状态修复
This commit is contained in:
1 parent
4227e3dd56
commit
e92549da48
176 files changed
+849
-650
No files matched your search
@@ -59,7 +59,7 @@ describe('request helpers', () => {
|
||||
await get('/bad');
|
||||
} catch (error /* error 是普通 JSON 请求必须保留结构化 envelope 的异常。 */) {
|
||||
expect(error).toBeInstanceOf(ApiError);
|
||||
expect(error).toMatchObject({ status: 400, code: 'bad_request', requestId: 'req-1', details: { field: 'title' }, payload });
|
||||
expect(error).toMatchObject({ status: 400, code: 'bad_request', requestId: 'req-1', request_id: 'req-1', details: { field: 'title' }, payload });
|
||||
}
|
||||
} /* 测试回调验证:surfaces unified backend errors。 */);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ApiErrorResponse } from '../api-contract';
|
||||
import type { ApiErrorResponse } from '../api-contract/common';
|
||||
|
||||
type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||
|
||||
@@ -35,6 +35,8 @@ export class ApiError extends Error {
|
||||
readonly code: string;
|
||||
// requestId 是服务端请求追踪标识,用户反馈问题时可安全提供给运维。
|
||||
readonly requestId?: string;
|
||||
// request_id 保持服务端错误契约的原始字段名,供需要透传原始 HTTP 语义的 feature adapter 使用。
|
||||
readonly request_id?: string;
|
||||
// details 是服务端提供的结构化恢复或审计信息,不包含客户端主动拼接的兼容字段。
|
||||
readonly details?: Record<string, unknown>;
|
||||
// payload 是保留给既有上传流程和诊断代码的原始响应载荷。
|
||||
@@ -47,6 +49,7 @@ export class ApiError extends Error {
|
||||
this.status = status;
|
||||
this.code = isApiErrorResponse(payload) ? payload.code : `http_${status}`;
|
||||
this.requestId = isApiErrorResponse(payload) ? payload.request_id : undefined;
|
||||
this.request_id = this.requestId;
|
||||
this.details = isApiErrorResponse(payload) ? payload.details : undefined;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user