mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 代码优化
This commit is contained in:
@ -15,7 +15,7 @@ type ErrorStatus = keyof typeof ERROR_STATUS;
|
||||
|
||||
/**
|
||||
* 处理axios请求失败的错误
|
||||
* @param error - 错误
|
||||
* @param axiosError - 错误
|
||||
*/
|
||||
export function handleAxiosError(axiosError: AxiosError) {
|
||||
const error: Service.RequestError = {
|
||||
@ -75,7 +75,7 @@ export function handleResponseError(response: AxiosResponse) {
|
||||
// 请求成功的状态码非200的错误
|
||||
const errorCode: ErrorStatus = response.status as ErrorStatus;
|
||||
const msg = ERROR_STATUS[errorCode] || DEFAULT_REQUEST_ERROR_MSG;
|
||||
Object.assign(error, { type: 'backend', code: errorCode, msg });
|
||||
Object.assign(error, { type: 'http', code: errorCode, msg });
|
||||
}
|
||||
|
||||
showErrorMsg(error);
|
||||
|
@ -18,15 +18,12 @@ function hasErrorMsg(error: Service.RequestError) {
|
||||
* @param error
|
||||
*/
|
||||
export function showErrorMsg(error: Service.RequestError) {
|
||||
if (!error.msg) return;
|
||||
if (!NO_ERROR_MSG_CODE.includes(error.code)) {
|
||||
if (!hasErrorMsg(error)) {
|
||||
addErrorMsg(error);
|
||||
window.console.warn(error.code, error.msg);
|
||||
window.$message?.error(error.msg, { duration: ERROR_MSG_DURATION });
|
||||
setTimeout(() => {
|
||||
removeErrorMsg(error);
|
||||
}, ERROR_MSG_DURATION);
|
||||
}
|
||||
}
|
||||
if (!error.msg || NO_ERROR_MSG_CODE.includes(error.code) || hasErrorMsg(error)) return;
|
||||
|
||||
addErrorMsg(error);
|
||||
window.console.warn(error.code, error.msg);
|
||||
window.$message?.error(error.msg, { duration: ERROR_MSG_DURATION });
|
||||
setTimeout(() => {
|
||||
removeErrorMsg(error);
|
||||
}, ERROR_MSG_DURATION);
|
||||
}
|
||||
|
@ -56,6 +56,6 @@ async function transformFile(formData: FormData, key: string, file: File[] | Fil
|
||||
);
|
||||
} else {
|
||||
// 单文件
|
||||
await formData.append(key, file);
|
||||
formData.append(key, file);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user