feat(common): 新增基础设施 HAR(网络/鉴权/日志/状态/工具)

This commit is contained in:
AndyChen1024
2026-09-11 16:22:45 +08:00
parent 2dc02b44c7
commit b73e74fa4a
16 changed files with 307 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
/**
* 统一错误模型:业务错误码 / HTTP 状态码 / 网络异常。
* 继承 Error 以符合 ArkTS 的 throw 限制(只能抛 Error 及其子类)。
*/
export class ApiError extends Error {
readonly code: number;
readonly isNetworkError: boolean;
constructor(code: number, message: string, isNetworkError: boolean = false) {
super(message);
this.code = code;
this.isNetworkError = isNetworkError;
}
static network(detail: string): ApiError {
return new ApiError(-1, `网络请求失败: ${detail}`, true);
}
static http(statusCode: number): ApiError {
return new ApiError(statusCode, `HTTP 状态码异常: ${statusCode}`, false);
}
static business(code: number, message: string): ApiError {
return new ApiError(code, message, false);
}
}