优化
This commit is contained in:
@@ -80,6 +80,12 @@ describe('API error diagnostics', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('does not expose local exception text in user-facing diagnostics', () => {
|
||||
expect(getApiErrorDetails(new Error('Error: socket failed\\n at internal/request.ts:42'))).toEqual({
|
||||
message: '接口请求失败', code: undefined, 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()
|
||||
|
||||
@@ -134,7 +134,8 @@ export function getApiErrorDetails(error: unknown, fallback = '接口请求失
|
||||
traceId: response?.traceId || undefined,
|
||||
}
|
||||
}
|
||||
return { message: error instanceof Error ? error.message : fallback }
|
||||
// Local/runtime errors are not user-facing API messages and may contain stack details.
|
||||
return { message: fallback }
|
||||
}
|
||||
|
||||
export function getApiErrorMessage(error: unknown, fallback = '接口请求失败'): string {
|
||||
|
||||
Reference in New Issue
Block a user