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:
@@ -105,21 +105,23 @@ export function createClientAxios(options = {}) {
|
||||
if (data.code === 0 || data.code === 200) {
|
||||
return data
|
||||
}
|
||||
|
||||
// 处理 401
|
||||
if (data.code === 401 && typeof on401 === 'function') {
|
||||
on401()
|
||||
}
|
||||
|
||||
// 处理 403(业务状态码)
|
||||
if (data.code === 403 && typeof on403 === 'function') {
|
||||
on403()
|
||||
}
|
||||
|
||||
// 抛出业务错误
|
||||
|
||||
// 创建业务错误对象
|
||||
const error = new Error(data?.message || data?.msg || '请求失败')
|
||||
error.code = data?.code
|
||||
error.data = data
|
||||
|
||||
// 处理 401
|
||||
if (data.code === 401 && typeof on401 === 'function') {
|
||||
on401(error)
|
||||
}
|
||||
|
||||
// 处理 403(业务状态码)
|
||||
if (data.code === 403 && typeof on403 === 'function') {
|
||||
on403(error)
|
||||
}
|
||||
|
||||
// 抛出业务错误
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
@@ -128,14 +130,14 @@ 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)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user