This commit is contained in:
2026-07-30 20:34:08 +08:00
parent dd0d365b03
commit f2fc40605e
2 changed files with 17 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { parseApiJsonResponse, parseJsonWithSafeIntegers } from '@chongchong/shared'
describe('safe integer API parsing', () => {
it('preserves backend long IDs as strings', () => {
expect(parseJsonWithSafeIntegers('{"id":2082674456475418625,"page":1}')).toEqual({
id: '2082674456475418625',
page: 1,
})
})
it('leaves non-JSON responses untouched', () => {
expect(parseApiJsonResponse('plain text')).toBe('plain text')
})
})
+2
View File
@@ -1,4 +1,5 @@
import axios, { type InternalAxiosRequestConfig } from 'axios'
import { parseApiJsonResponse } from '@chongchong/shared'
export interface ApiEnvelope<T> {
code: string
@@ -37,6 +38,7 @@ export interface ApiErrorDetails {
export const http = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL || '/api',
timeout: 15_000,
transformResponse: [(data: unknown) => parseApiJsonResponse(data)],
})
type RetryableRequestConfig = InternalAxiosRequestConfig & { _authRetry?: boolean }