diff --git a/src/utils/request.ts b/src/utils/request.ts index 517d556..d89714e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -41,9 +41,13 @@ http.interceptors.response.use( const body = response.data as ApiEnvelope | undefined if (body && typeof body === 'object' && 'code' in body) { if (body.code === 0) return response - // 业务级 code:401 (如 /openapi/** 带 token 时 Spring Security 返未授权) - // 不清 token 不跳登录,只 reject 给调用方处理 - // 真正的 token 过期走 error 拦截器 (HTTP status 401) + // 业务级 code:401 + // 未登录(无 token)访问受保护接口(如 /sys/menu/nav)→ 跳登录页 + // 已登录但权限不足(如 /openapi/** 带 token 被 Spring Security 拒)→ 保持 reject 给调用方 + if (body.code === 401 && !localStorage.getItem(STORAGE_KEY)) { + handleAuthExpired() + return Promise.reject(body) + } return Promise.reject(body) } return response