优化
This commit is contained in:
@@ -63,6 +63,23 @@ describe('API error diagnostics', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('explains a proxy 413 response without a JSON error envelope', () => {
|
||||
const error = new axios.AxiosError('Request failed', 'ERR_BAD_REQUEST', undefined, undefined, {
|
||||
status: 413,
|
||||
statusText: 'Payload Too Large',
|
||||
headers: {},
|
||||
config: { headers: new AxiosHeaders() },
|
||||
data: '<html>Request Entity Too Large</html>',
|
||||
})
|
||||
|
||||
expect(getApiErrorDetails(error)).toEqual({
|
||||
message: '上传文件的请求体过大,服务器已拒绝;请压缩后重试,如文件未超过 5MB,请联系管理员检查网关上传限制',
|
||||
code: 'HTTP_413',
|
||||
requestId: undefined,
|
||||
traceId: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('notifies session expiry once when concurrent 401 requests share a failed refresh', async () => {
|
||||
const refresh = vi.fn(async () => { throw new Error('refresh token expired') })
|
||||
const expired = vi.fn()
|
||||
|
||||
@@ -123,8 +123,12 @@ export function getApiErrorDetails(error: unknown, fallback = '接口请求失
|
||||
requestId?: string | null
|
||||
traceId?: string | null
|
||||
} | undefined
|
||||
const status = error.response?.status
|
||||
const statusMessage = status === 413
|
||||
? '上传文件的请求体过大,服务器已拒绝;请压缩后重试,如文件未超过 5MB,请联系管理员检查网关上传限制'
|
||||
: undefined
|
||||
return {
|
||||
message: response?.message || response?.error || fallback,
|
||||
message: response?.message || response?.error || statusMessage || fallback,
|
||||
code: response?.code || (error.response?.status ? `HTTP_${error.response.status}` : undefined),
|
||||
requestId: response?.requestId || undefined,
|
||||
traceId: response?.traceId || undefined,
|
||||
|
||||
Reference in New Issue
Block a user