离谱的问题解决放肆,上级要求

This commit is contained in:
海龙 2025-08-31 03:47:45 +08:00
parent f0f71a7f40
commit 85f68a5462
3 changed files with 12 additions and 5 deletions

View File

@ -50,6 +50,7 @@ request.interceptors.response.use(
(response: AxiosResponse) => {
// 检查业务状态码
if (response.data?.code !== 0 && response.data?.code !== 202) {
console.log('response', response)
// 处理业务层面的错误
const businessCode = response.data?.code;
const errorMessage = response.data?.message;

View File

@ -2,8 +2,10 @@
import { useEffect, useState } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { checkAuth, getUserProfile, isAuthenticated } from '@/lib/auth';
import { checkAuth, clearAuthData, getUserProfile, isAuthenticated } from '@/lib/auth';
import GlobalLoad from '../common/GlobalLoad';
import { message } from 'antd';
import { errorHandle } from '@/api/errorHandle';
interface AuthGuardProps {
children: React.ReactNode;
@ -42,9 +44,13 @@ export default function AuthGuard({ children }: AuthGuardProps) {
} else {
router.push('/login');
}
} catch (error) {
console.error('Auth verification failed:', error);
} catch (errorCode:any) {
// 强制的领导要求401和502都跳转到登录页 其他的不管
if(errorCode.message == 401||errorCode.message == 502){
router.push('/login');
clearAuthData();
}
errorHandle(errorCode.message)
} finally {
setIsLoading(false);
}

View File

@ -277,7 +277,7 @@ export const getUserProfile = async (): Promise<any> => {
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
throw new Error(response.status.toString());
}
const data = await response.json();