优化
This commit is contained in:
+10
-2
@@ -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'
|
||||
? '当前账号无权访问该数据,请联系管理员确认权限'
|
||||
|
||||
Reference in New Issue
Block a user