fix: 区分登录失败和 Token 过期的 401 错误
- 登录/注册接口的 401 不触发全局拦截器 - 让认证错误正常传递到表单组件显示 i18n 翻译 - 只有其他接口的 401 才认为是 Token 过期 - 移除调试日志 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a66bcca38b
commit
2f290eeedd
|
|
@ -77,6 +77,16 @@ export const createFetchWithLogger = (options: FetchLoggerOptions = {}) => {
|
|||
|
||||
// 401 未授权处理
|
||||
if (response.status === 401 && !isRedirecting) {
|
||||
// 检查是否是登录/注册接口的 401 错误(用户名密码错误)
|
||||
const isAuthEndpoint = url.includes('/sign-in/') || url.includes('/sign-up/')
|
||||
|
||||
// 如果是认证接口的 401,不处理,让错误传递到组件
|
||||
if (isAuthEndpoint) {
|
||||
console.log('🔐 认证接口返回 401,不处理')
|
||||
return response
|
||||
}
|
||||
|
||||
// 其他接口的 401 才认为是 Token 过期
|
||||
console.warn('🔐 401 未授权,跳转到登录页')
|
||||
isRedirecting = true
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue