🔨 优化错误提示.

This commit is contained in:
lijiahangmax
2025-10-17 14:14:34 +08:00
parent f648e18557
commit 0649c4e3de
5 changed files with 26 additions and 5 deletions

View File

@@ -0,0 +1,12 @@
import type { AxiosResponse } from 'axios';
// api 错误
export class ApiError extends Error {
data: AxiosResponse;
constructor(message: string, data: AxiosResponse) {
super(message);
this.name = 'ApiError';
this.data = data;
}
}

View File

@@ -5,6 +5,7 @@ import { useUserStore } from '@/store';
import { getToken } from '@/utils/auth';
import { httpBaseUrl } from '@/utils/env';
import { reLoginTipsKey } from '@/types/symbol';
import { ApiError } from '@/api/error';
axios.defaults.timeout = 15000;
axios.defaults.setAuthorization = true;
@@ -72,7 +73,7 @@ axios.interceptors.response.use(
});
}
}
return Promise.reject(new Error(res.msg || 'Error'));
return Promise.reject(new ApiError(res.msg || 'Error', res));
},
(error) => {
// 判断是否弹出请求错误信息

View File

@@ -1,5 +1,5 @@
import type { MenuQueryResponse } from '@/api/system/menu';
import type { AxiosResponse } from 'axios';
import type { HttpResponse } from '@/types/global';
import axios from 'axios';
/**
@@ -36,7 +36,7 @@ export interface UserUpdatePasswordResponse {
* 获取用户聚合信息
*/
export function getUserAggregateInfo() {
return axios.get<AxiosResponse<UserAggregateResponse>>('/infra/user-aggregate/user', {
return axios.get<HttpResponse<UserAggregateResponse>>('/infra/user-aggregate/user', {
unwrap: true
});
}