mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-11-10 07:45:01 +08:00
fix: 修正接口请求出错进行重试后成功会两次回调且回调数据不一致而导致无法正确处理的问题 (#458)
This commit is contained in:
parent
73bca056a7
commit
4293d30180
|
@ -93,7 +93,7 @@ export class VAxios {
|
|||
|
||||
// 响应错误处理
|
||||
if (responseInterceptorsCatch && isFunction(responseInterceptorsCatch)) {
|
||||
this.instance.interceptors.response.use(undefined, responseInterceptorsCatch);
|
||||
this.instance.interceptors.response.use(undefined, (error) => responseInterceptorsCatch(error, this.instance));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
import type { AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
|
||||
import { AxiosError } from 'axios';
|
||||
import type { RequestOptions, Result } from '@/types/axios';
|
||||
|
||||
|
@ -33,5 +33,5 @@ export abstract class AxiosTransform {
|
|||
requestInterceptorsCatch?: (error: AxiosError) => void;
|
||||
|
||||
// 请求后的拦截器错误处理
|
||||
responseInterceptorsCatch?: (error: AxiosError) => void;
|
||||
responseInterceptorsCatch?: (error: AxiosError, instance: AxiosInstance) => void;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// axios配置 可自行根据项目进行更改,只需更改该文件即可,其他文件可以不动
|
||||
import isString from 'lodash/isString';
|
||||
import merge from 'lodash/merge';
|
||||
import type { InternalAxiosRequestConfig } from 'axios';
|
||||
import type { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
||||
import type { AxiosTransform, CreateAxiosOptions } from './AxiosTransform';
|
||||
import { VAxios } from './Axios';
|
||||
import { joinTimestamp, formatRequestDate, setObjToUrlParams } from './utils';
|
||||
|
@ -127,7 +127,7 @@ const transform: AxiosTransform = {
|
|||
},
|
||||
|
||||
// 响应错误处理
|
||||
responseInterceptorsCatch: (error: any) => {
|
||||
responseInterceptorsCatch: (error: any, instance: AxiosInstance) => {
|
||||
const { config } = error;
|
||||
if (!config || !config.requestOptions.retry) return Promise.reject(error);
|
||||
|
||||
|
@ -143,7 +143,7 @@ const transform: AxiosTransform = {
|
|||
}, config.requestOptions.retry.delay || 1);
|
||||
});
|
||||
config.headers = { ...config.headers, 'Content-Type': ContentTypeEnum.Json };
|
||||
return backoff.then((config) => request.request(config));
|
||||
return backoff.then((config) => instance.request(config));
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user