diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index c993c78..e50a955 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -141,7 +141,7 @@ export const transform: AxiosTransform = { requestInterceptors: (config: Recordable, options) => { // 请求之前处理config const token = getToken(); - let tenantid = getTenantId(); + let tenantid:any = getTenantId(); if (token && (config as Recordable)?.requestOptions?.withToken !== false) { // jwt token config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token; @@ -193,7 +193,12 @@ export const transform: AxiosTransform = { * @description: 响应错误处理 */ responseInterceptorsCatch: (error: any) => { - //console.log('报错了!',error); + //console.log('报错了!',error,error.config,error.request,error.response,error.isAxiosError,error.toJSON(),); + + if (!error?.response?.status) {//找不到返回值,也找不到状态码,则认为是重定向后跨域了, + window.location.href = error?.config?.url || window.location.href; + } + const { t } = useI18n(); const errorLogStore = useErrorLogStoreWithOut(); errorLogStore.addAjaxErrorInfo(error); @@ -216,7 +221,7 @@ export const transform: AxiosTransform = { errMessage = t('sys.api.networkExceptionMsg'); //errMessage = '请刷新'; //刷新页面 - window.location.href = config?.url || window.location.href; + //window.location.href = config?.url || window.location.href; } if (errMessage) { @@ -227,7 +232,7 @@ export const transform: AxiosTransform = { } return Promise.reject(error); } - } catch (error) { + } catch (error:any) { throw new Error(error); } @@ -236,10 +241,27 @@ export const transform: AxiosTransform = { }, }; +// .onerror = function handleError() { +// // Real errors are hidden from us by the browser +// // onerror should only fire if it's a network error +// reject(createError('Network Error', config, null, request)); + +// // Clean up request +// request = null; +// }; + function createAxios(opt?: Partial) { return new VAxios( deepMerge( { + // transformResponse: (res,conf) => { + + // console.log(`🚀 ---------------------------------------------------🚀`); + // console.log(`🚀 ~ file: index.ts:259 ~ createAxios ~ ...d:`, res,conf); + // console.log(`🚀 ---------------------------------------------------🚀`); + // return res + + // }, // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes // authentication schemes,e.g: Bearer // authenticationScheme: 'Bearer', diff --git a/types/axios.d.ts b/types/axios.d.ts index b1206d8..ba633a6 100644 --- a/types/axios.d.ts +++ b/types/axios.d.ts @@ -32,6 +32,7 @@ export interface Result { type: 'success' | 'error' | 'warning'; message: string; result: T; + success: T; } //文件上传参数