diff --git a/frontend/api/axios/client.js b/frontend/api/axios/client.js index 648522c16d..d58711c527 100644 --- a/frontend/api/axios/client.js +++ b/frontend/api/axios/client.js @@ -102,7 +102,7 @@ export function createClientAxios(options = {}) { client.interceptors.response.use( (response) => { const data = response.data - + // 检查业务状态码 if (data && typeof data.code === 'number') { if (data.code === 0 || data.code === 200) { @@ -114,29 +114,27 @@ export function createClientAxios(options = {}) { error.code = data?.code error.data = data - // 处理 401 + // 业务码 401/403 只在响应拦截器处理,避免重复处理 if (data.code === 401 && typeof on401 === 'function') { on401(error) } - // 处理 403(业务状态码) if (data.code === 403 && typeof on403 === 'function') { on403(error) } - // 抛出业务错误 + // 抛出错误,业务代码可以捕获 return Promise.reject(error) } - + return data }, (error) => { - // 处理 HTTP 401 + // HTTP 状态码 401/403 只在错误拦截器处理 if (error.response?.status === 401 && typeof on401 === 'function') { on401(error) } - // 处理 HTTP 403 if (error.response?.status === 403 && typeof on403 === 'function') { on403(error) }