fix: skip error handler in root path
This commit is contained in:
+7
-15
@@ -13,7 +13,6 @@ import {
|
|||||||
writeState
|
writeState
|
||||||
} from '@/utils/localstore/index';
|
} from '@/utils/localstore/index';
|
||||||
import { RequestConfig, history } from '@umijs/max';
|
import { RequestConfig, history } from '@umijs/max';
|
||||||
import { message } from 'antd';
|
|
||||||
|
|
||||||
const loginPath = '/login';
|
const loginPath = '/login';
|
||||||
|
|
||||||
@@ -49,27 +48,18 @@ export async function getInitialState(): Promise<{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchUserInfo = async (): Promise<Global.UserInfo> => {
|
const fetchUserInfo = async (config?: {
|
||||||
|
skipErrorHandler?: boolean;
|
||||||
|
}): Promise<Global.UserInfo> => {
|
||||||
try {
|
try {
|
||||||
const data = await queryCurrentUserState({
|
const data = await queryCurrentUserState({
|
||||||
skipErrorHandler: true
|
skipErrorHandler: config?.skipErrorHandler ?? false
|
||||||
});
|
});
|
||||||
if (data.is_admin) {
|
if (data.is_admin) {
|
||||||
getUpdateCheck();
|
getUpdateCheck();
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const data = error?.response?.data;
|
|
||||||
if (data?.code === 401) {
|
|
||||||
message.error({
|
|
||||||
content: (
|
|
||||||
<div>
|
|
||||||
<span>{data?.message}</span>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
duration: 5
|
|
||||||
});
|
|
||||||
}
|
|
||||||
history.push(loginPath);
|
history.push(loginPath);
|
||||||
}
|
}
|
||||||
return {} as Global.UserInfo;
|
return {} as Global.UserInfo;
|
||||||
@@ -91,7 +81,9 @@ export async function getInitialState(): Promise<{
|
|||||||
getAppVersionInfo();
|
getAppVersionInfo();
|
||||||
|
|
||||||
if (![loginPath].includes(location.pathname)) {
|
if (![loginPath].includes(location.pathname)) {
|
||||||
const userInfo = await fetchUserInfo();
|
const userInfo = await fetchUserInfo({
|
||||||
|
skipErrorHandler: location.pathname === '/'
|
||||||
|
});
|
||||||
checkDefaultPage(userInfo);
|
checkDefaultPage(userInfo);
|
||||||
return {
|
return {
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
|
|||||||
Reference in New Issue
Block a user