File tree Expand file tree Collapse file tree 3 files changed +25
-14
lines changed
Expand file tree Collapse file tree 3 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { Agent } from "undici";
44import { z } from "zod/v4" ;
55
66import {
7- createValidationInterceptor ,
7+ attachValidationInterceptor ,
88 type ValidationConfig ,
99} from "@/utils/axios/interceptors/validation" ;
1010import { encode } from "@/utils/base64" ;
@@ -46,7 +46,7 @@ export class LocalApiClient {
4646
4747 constructor ( options : LocalApiClientOptions ) {
4848 this . options = localApiClientOptionsSchema . parse ( options ) ;
49- createValidationInterceptor ( this . axios ) ;
49+ attachValidationInterceptor ( this . axios ) ;
5050 }
5151
5252 private getServerUrl ( ) {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
1010} from "@/helpers/servers" ;
1111import { zv } from "@/schemas/valorant" ;
1212import {
13- createValidationInterceptor ,
13+ attachValidationInterceptor ,
1414 type ValidationConfig ,
1515} from "@/utils/axios/interceptors/validation" ;
1616import { encode } from "@/utils/base64" ;
@@ -57,7 +57,7 @@ export class RemoteApiClient {
5757
5858 constructor ( options : RemoteApiClientOptions ) {
5959 this . options = remoteApiClientOptionsSchema . parse ( options ) ;
60- createValidationInterceptor ( this . axios ) ;
60+ attachValidationInterceptor ( this . axios ) ;
6161 }
6262
6363 get puuid ( ) {
Original file line number Diff line number Diff line change @@ -9,15 +9,26 @@ export type ValidationConfig<TSchema extends StandardSchemaV1> = {
99 [ SCHEMA_KEY ] ?: TSchema ;
1010} ;
1111
12- export function createValidationInterceptor ( axiosInstance : AxiosInstance ) {
13- return axiosInstance . interceptors . response . use ( async response => {
14- if (
15- SCHEMA_KEY in response . config &&
16- isStandardSchema ( response . config [ SCHEMA_KEY ] )
17- ) {
18- validate ( response . config [ SCHEMA_KEY ] , response . data ) ;
19- }
12+ export function attachValidationInterceptor ( axiosInstance : AxiosInstance ) {
13+ const responseInterceptorId = axiosInstance . interceptors . response . use (
14+ async response => {
15+ if (
16+ SCHEMA_KEY in response . config &&
17+ isStandardSchema ( response . config [ SCHEMA_KEY ] )
18+ ) {
19+ response . data = await validate (
20+ response . config [ SCHEMA_KEY ] ,
21+ response . data ,
22+ ) ;
23+ }
2024
21- return response ;
22- } ) ;
25+ return response ;
26+ } ,
27+ ) ;
28+
29+ return {
30+ eject ( ) {
31+ axiosInstance . interceptors . response . eject ( responseInterceptorId ) ;
32+ } ,
33+ } ;
2334}
You can’t perform that action at this time.
0 commit comments