fix: 修复clientAxios中on401/on403回调未传递error参数的问题

问题:
- client.js中调用on401()和on403()时未传递error对象
- 导致http.js中接收到undefined的error参数
- 影响AuthService.handleAuthError的错误处理逻辑

修复:
- 业务码401/403:先创建error对象,再传递给回调函数
- HTTP状态码401/403:直接传递error对象给回调函数
- 确保error对象包含完整的错误信息(code、data等)

影响范围:
- frontend/api/axios/client.js

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-25 01:00:20 +08:00
parent fb6d18b4f5
commit a32f118281

View File

@@ -106,20 +106,22 @@ export function createClientAxios(options = {}) {
return data
}
// 创建业务错误对象
const error = new Error(data?.message || data?.msg || '请求失败')
error.code = data?.code
error.data = data
// 处理 401
if (data.code === 401 && typeof on401 === 'function') {
on401()
on401(error)
}
// 处理 403业务状态码
if (data.code === 403 && typeof on403 === 'function') {
on403()
on403(error)
}
// 抛出业务错误
const error = new Error(data?.message || data?.msg || '请求失败')
error.code = data?.code
error.data = data
return Promise.reject(error)
}
@@ -128,12 +130,12 @@ export function createClientAxios(options = {}) {
(error) => {
// 处理 HTTP 401
if (error.response?.status === 401 && typeof on401 === 'function') {
on401()
on401(error)
}
// 处理 HTTP 403
if (error.response?.status === 403 && typeof on403 === 'function') {
on403()
on403(error)
}
return Promise.reject(error)