This commit is contained in:
2026-08-14 18:50:11 +08:00
parent 93e0294ec0
commit 44ee2be246
9 changed files with 196 additions and 29 deletions
+10 -2
View File
@@ -35,6 +35,10 @@ export interface ApiErrorDetails {
traceId?: string
}
export interface ApiErrorDetailsOptions {
preserveAuthenticationMessage?: boolean
}
export const http = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
timeout: 15_000,
@@ -113,9 +117,13 @@ export function unwrapApiResponse<T>(response: ApiEnvelope<T>): T {
return response.data
}
export function getApiErrorDetails(error: unknown, fallback = '接口请求失败'): ApiErrorDetails {
export function getApiErrorDetails(
error: unknown,
fallback = '接口请求失败',
options: ApiErrorDetailsOptions = {},
): ApiErrorDetails {
if (error instanceof ApiResponseError) {
const message = error.code === 'A0401'
const message = error.code === 'A0401' && !options.preserveAuthenticationMessage
? '登录状态已失效,请重新登录'
: error.code === 'A0403'
? '当前账号无权访问该数据,请联系管理员确认权限'