|
@@ -13,7 +13,7 @@ import { isString } from '@/core/utils/is';
|
|
|
import { setObjToUrlParams, deepMerge } from '@/core/utils';
|
|
import { setObjToUrlParams, deepMerge } from '@/core/utils';
|
|
|
import { useErrorLogStoreWithOut } from '@/core/store/modules/errorLog';
|
|
import { useErrorLogStoreWithOut } from '@/core/store/modules/errorLog';
|
|
|
import { useI18n } from '@/core/hooks/web/useI18n';
|
|
import { useI18n } from '@/core/hooks/web/useI18n';
|
|
|
-import { joinTimestamp, formatRequestDate, normalizeEmptyRequestValue } from './helper';
|
|
|
|
|
|
|
+import { joinTimestamp, formatRequestDate, normalizeEmptyRequestValue, appendApiUrl } from './helper';
|
|
|
import { handleUnauthorizedRedirect } from './unauthorized';
|
|
import { handleUnauthorizedRedirect } from './unauthorized';
|
|
|
|
|
|
|
|
const globSetting = useGlobSetting();
|
|
const globSetting = useGlobSetting();
|
|
@@ -43,6 +43,8 @@ const transform: AxiosTransform = {
|
|
|
// 错误的时候返回
|
|
// 错误的时候返回
|
|
|
|
|
|
|
|
const { data, config } = res;
|
|
const { data, config } = res;
|
|
|
|
|
+ // 本次请求的接口地址(已拼接 urlPrefix),用于错误提示中直接定位接口
|
|
|
|
|
+ const requestUrl = config?.url || '';
|
|
|
// if (!data) { // boolean false return error
|
|
// if (!data) { // boolean false return error
|
|
|
// // return '[HTTP] Request has no return value';
|
|
// // return '[HTTP] Request has no return value';
|
|
|
// throw new Error(t('sys.api.apiRequestFailed'));
|
|
// throw new Error(t('sys.api.apiRequestFailed'));
|
|
@@ -56,9 +58,9 @@ const transform: AxiosTransform = {
|
|
|
if (code !== 200) {
|
|
if (code !== 200) {
|
|
|
if (code === 401) {
|
|
if (code === 401) {
|
|
|
handleUnauthorizedRedirect();
|
|
handleUnauthorizedRedirect();
|
|
|
- throw new Error(message || t('sys.api.apiRequestFailed'));
|
|
|
|
|
|
|
+ throw new Error(appendApiUrl(message || t('sys.api.apiRequestFailed'), requestUrl));
|
|
|
}
|
|
}
|
|
|
- const errorMessage = message || t('sys.api.apiRequestFailed');
|
|
|
|
|
|
|
+ const errorMessage = appendApiUrl(message || t('sys.api.apiRequestFailed'), requestUrl);
|
|
|
if (skipErrorMessage) {
|
|
if (skipErrorMessage) {
|
|
|
throw new Error(errorMessage);
|
|
throw new Error(errorMessage);
|
|
|
}
|
|
}
|
|
@@ -210,7 +212,8 @@ const transform: AxiosTransform = {
|
|
|
const skipErrorMessage = !!config?.requestOptions?.skipErrorMessage;
|
|
const skipErrorMessage = !!config?.requestOptions?.skipErrorMessage;
|
|
|
const msg: string = response?.data?.message ?? '';
|
|
const msg: string = response?.data?.message ?? '';
|
|
|
const err: string = error?.toString?.() ?? '';
|
|
const err: string = error?.toString?.() ?? '';
|
|
|
- const urlPath = response?.config?.url || '';
|
|
|
|
|
|
|
+ // 接口地址:网络异常/超时等无 response 的场景,退化为取 error.config.url
|
|
|
|
|
+ const urlPath = response?.config?.url || config?.url || '';
|
|
|
if (skipErrorMessage) {
|
|
if (skipErrorMessage) {
|
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
|
}
|
|
}
|
|
@@ -238,7 +241,7 @@ const transform: AxiosTransform = {
|
|
|
}
|
|
}
|
|
|
if (!isShowMessage) {
|
|
if (!isShowMessage) {
|
|
|
isShowMessage = true;
|
|
isShowMessage = true;
|
|
|
- showMessage({ content: msg || errMessage }, 'error');
|
|
|
|
|
|
|
+ showMessage({ content: appendApiUrl(msg || errMessage, urlPath) }, 'error');
|
|
|
setTimeout(() => (isShowMessage = false), 1000);
|
|
setTimeout(() => (isShowMessage = false), 1000);
|
|
|
}
|
|
}
|
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
@@ -251,7 +254,7 @@ const transform: AxiosTransform = {
|
|
|
handleUnauthorizedRedirect();
|
|
handleUnauthorizedRedirect();
|
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
|
}
|
|
}
|
|
|
- checkStatus(response?.status, msg, errorMessageMode);
|
|
|
|
|
|
|
+ checkStatus(response?.status, msg, errorMessageMode, urlPath);
|
|
|
return Promise.reject(error);
|
|
return Promise.reject(error);
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|