This commit is contained in:
2026-08-12 12:35:32 +08:00
parent 11e085e30f
commit 4fb8b85c13
22 changed files with 161 additions and 47 deletions
+6
View File
@@ -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()
+2 -1
View File
@@ -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 {