forked from 77media/video-flow
离谱的问题解决放肆,上级要求
This commit is contained in:
parent
f0f71a7f40
commit
85f68a5462
@ -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;
|
||||
|
||||
@ -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);
|
||||
router.push('/login');
|
||||
} catch (errorCode:any) {
|
||||
// 强制的领导要求,401和502都跳转到登录页 其他的不管
|
||||
if(errorCode.message == 401||errorCode.message == 502){
|
||||
router.push('/login');
|
||||
clearAuthData();
|
||||
}
|
||||
errorHandle(errorCode.message)
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user