1
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user