feat(fetchClient): handle 403 status with error message and redirect

This commit is contained in:
shiyu
2025-06-02 12:16:47 +08:00
parent d015701078
commit 6243b9b62a
+14 -3
View File
@@ -20,10 +20,11 @@ export async function fetchApi<T = any>(
headers,
});
if (response.status === 401) {
if (response.status === 401 && !url.includes('/login')) {
clearAuthData();
const message = encodeURIComponent('授权过期重新登录');
window.location.href = `/login?message=${message}`;
const { message } = await import('antd');
message.error('授权过期重新登录');
window.location.href = `/login`;
return {
success: false,
message: '授权过期重新登录',
@@ -31,6 +32,16 @@ export async function fetchApi<T = any>(
} as BaseResult<T>;
}
if (response.status === 403) {
const { message } = await import('antd');
message.error('没有权限');
return {
success: false,
message: '没有权限',
code: 403,
} as BaseResult<T>;
}
const data = await response.json();
return data as BaseResult<T>;
} catch (error) {