chore: 合并 gitee 上游 master(依赖/配置)并保留本地定制
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import axios, { type InternalAxiosRequestConfig, type AxiosResponse } from "axios";
|
||||
import axios, { type AxiosResponse } from "axios";
|
||||
import qs from "qs";
|
||||
|
||||
import { ApiCodeEnum } from "@/enums/api";
|
||||
import { AuthStorage } from "@/utils/auth";
|
||||
import { useUserStoreHook } from "@/stores/user";
|
||||
import { usePermissionStoreHook } from "@/stores/permission";
|
||||
import { AuthStorage } from "@/utils/auth";
|
||||
import type { ApiResult } from "@/api/common";
|
||||
|
||||
// 防止同一请求在 token 刷新后重复进入重试,导致死循环
|
||||
@@ -41,7 +41,7 @@ function setupInterceptors(instance: typeof http) {
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error)
|
||||
(error) => Promise.reject(error),
|
||||
);
|
||||
|
||||
instance.interceptors.response.use(
|
||||
@@ -64,6 +64,11 @@ function setupInterceptors(instance: typeof http) {
|
||||
},
|
||||
|
||||
async (error) => {
|
||||
// 请求被主动取消(如切换路由取消未完成请求),不再提示错误
|
||||
if (axios.isCancel(error)) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
const { config, response } = error;
|
||||
|
||||
if (!response) {
|
||||
@@ -71,6 +76,16 @@ function setupInterceptors(instance: typeof http) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
// 调用方声明静默的错误状态码(如轮询 401/403 不弹错误),直接透传
|
||||
if (
|
||||
response &&
|
||||
(
|
||||
error.config as { silentErrorStatuses?: number[] } | undefined
|
||||
)?.silentErrorStatuses?.includes(response.status)
|
||||
) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
const { code, msg } = response.data as ApiResult;
|
||||
|
||||
// Token 过期
|
||||
@@ -114,7 +129,7 @@ function setupInterceptors(instance: typeof http) {
|
||||
|
||||
ElMessage.error(msg || "请求失败");
|
||||
return Promise.reject(new Error(msg || "请求失败"));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user