Skip to content

Commit 14de6da

Browse files
committed
fix: 修复 Axios 错误处理中的类型断言问题
在 Http 类的错误处理逻辑中,修改了对 apiError 的类型断言方式,以确保正确地将 statusCode 和 response 属性添加到 Error 对象中。使用 `unknown as Record<string, unknown>` 来替代之前的 `Record<string, unknown>` 方式,以增强类型安全性和兼容性。
1 parent bcc9bcd commit 14de6da

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

frontend/lib/axios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class Http {
108108
// 从 ApiResponse 中提取错误信息
109109
const message = data?.message || `请求失败 (${status})`;
110110
const apiError = new Error(message);
111-
(apiError as Record<string, unknown>).statusCode = status;
112-
(apiError as Record<string, unknown>).response = error.response;
111+
(apiError as unknown as Record<string, unknown>).statusCode = status;
112+
(apiError as unknown as Record<string, unknown>).response = error.response;
113113
return Promise.reject(apiError);
114114
} else if (error.request) {
115115
return Promise.reject(new Error('网络错误,无法连接到服务器'));

0 commit comments

Comments
 (0)