fix: 取消重复请求,错误处理 (#2184)
This commit is contained in:
parent
dda27477af
commit
b1f78c6696
|
|
@ -18,6 +18,7 @@ import { useI18n } from '/@/hooks/web/useI18n';
|
||||||
import { joinTimestamp, formatRequestDate } from './helper';
|
import { joinTimestamp, formatRequestDate } from './helper';
|
||||||
import { useUserStoreWithOut } from '/@/store/modules/user';
|
import { useUserStoreWithOut } from '/@/store/modules/user';
|
||||||
import { AxiosRetry } from '/@/utils/http/axios/axiosRetry';
|
import { AxiosRetry } from '/@/utils/http/axios/axiosRetry';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
const globSetting = useGlobSetting();
|
const globSetting = useGlobSetting();
|
||||||
const urlPrefix = globSetting.urlPrefix;
|
const urlPrefix = globSetting.urlPrefix;
|
||||||
|
|
@ -111,7 +112,11 @@ const transform: AxiosTransform = {
|
||||||
} else {
|
} else {
|
||||||
if (!isString(params)) {
|
if (!isString(params)) {
|
||||||
formatDate && formatRequestDate(params);
|
formatDate && formatRequestDate(params);
|
||||||
if (Reflect.has(config, 'data') && config.data && (Object.keys(config.data).length > 0 || config.data instanceof FormData)) {
|
if (
|
||||||
|
Reflect.has(config, 'data') &&
|
||||||
|
config.data &&
|
||||||
|
(Object.keys(config.data).length > 0 || config.data instanceof FormData)
|
||||||
|
) {
|
||||||
config.data = data;
|
config.data = data;
|
||||||
config.params = params;
|
config.params = params;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -169,6 +174,10 @@ const transform: AxiosTransform = {
|
||||||
const err: string = error?.toString?.() ?? '';
|
const err: string = error?.toString?.() ?? '';
|
||||||
let errMessage = '';
|
let errMessage = '';
|
||||||
|
|
||||||
|
if (axios.isCancel(error)) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) {
|
if (code === 'ECONNABORTED' && message.indexOf('timeout') !== -1) {
|
||||||
errMessage = t('sys.api.apiTimeoutMessage');
|
errMessage = t('sys.api.apiTimeoutMessage');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue