forked from 77media/video-flow
离谱的问题解决放肆,上级要求
This commit is contained in:
parent
f0f71a7f40
commit
85f68a5462
@ -50,6 +50,7 @@ request.interceptors.response.use(
|
|||||||
(response: AxiosResponse) => {
|
(response: AxiosResponse) => {
|
||||||
// 检查业务状态码
|
// 检查业务状态码
|
||||||
if (response.data?.code !== 0 && response.data?.code !== 202) {
|
if (response.data?.code !== 0 && response.data?.code !== 202) {
|
||||||
|
console.log('response', response)
|
||||||
// 处理业务层面的错误
|
// 处理业务层面的错误
|
||||||
const businessCode = response.data?.code;
|
const businessCode = response.data?.code;
|
||||||
const errorMessage = response.data?.message;
|
const errorMessage = response.data?.message;
|
||||||
|
|||||||
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useRouter, usePathname } from 'next/navigation';
|
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 GlobalLoad from '../common/GlobalLoad';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import { errorHandle } from '@/api/errorHandle';
|
||||||
|
|
||||||
interface AuthGuardProps {
|
interface AuthGuardProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -42,9 +44,13 @@ export default function AuthGuard({ children }: AuthGuardProps) {
|
|||||||
} else {
|
} else {
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (errorCode:any) {
|
||||||
console.error('Auth verification failed:', error);
|
// 强制的领导要求,401和502都跳转到登录页 其他的不管
|
||||||
router.push('/login');
|
if(errorCode.message == 401||errorCode.message == 502){
|
||||||
|
router.push('/login');
|
||||||
|
clearAuthData();
|
||||||
|
}
|
||||||
|
errorHandle(errorCode.message)
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -277,7 +277,7 @@ export const getUserProfile = async (): Promise<any> => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(response.status.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user