From a32f118281bce537d923bb74f8e30c4a5f349b85 Mon Sep 17 00:00:00 2001 From: sion123 <450702724@qq.com> Date: Tue, 25 Nov 2025 01:00:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DclientAxios=E4=B8=ADon?= =?UTF-8?q?401/on403=E5=9B=9E=E8=B0=83=E6=9C=AA=E4=BC=A0=E9=80=92error?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 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 --- frontend/api/axios/client.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/frontend/api/axios/client.js b/frontend/api/axios/client.js index eed197a60b..73c903bf86 100644 --- a/frontend/api/axios/client.js +++ b/frontend/api/axios/client.js @@ -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) } )