@@ -18,45 +18,48 @@ const axiosInstance = axios.create({
1818
1919// Add a request interceptor
2020axiosInstance . interceptors . request . use (
21- function ( config ) {
22- // Do something before request is sent
23- if ( ! config . url || ! config . params ) {
24- return config ;
25- }
26-
27- Object . entries < any > ( config . params ) . forEach ( ( [ key , value ] ) => {
28- const stringToSearch = `{${ key } }` ;
29- if ( config . url !== undefined && config . url . search ( stringToSearch ) !== - 1 ) {
30- config . url = config . url . replace ( `{${ key } }` , encodeURIComponent ( value ) ) ;
31- delete config . params [ key ] ;
32- }
33- } ) ;
21+ ( config ) => {
22+ // Do something before request is sent
23+ if ( ! config . url || ! config . params ) {
24+ return config ;
25+ }
3426
35- return config ;
36- } ,
37- function ( error ) {
38- // Do something with request error
39- return Promise . reject ( error ) ;
27+ for ( const [ key , value ] of Object . entries < string > ( config . params ) ) {
28+ const stringToSearch = `{${ key } }` ;
29+ if (
30+ config . url !== undefined &&
31+ config . url . search ( stringToSearch ) !== - 1
32+ ) {
33+ config . url = config . url . replace ( `{${ key } }` , encodeURIComponent ( value ) ) ;
34+ delete config . params [ key ] ;
35+ }
4036 }
37+
38+ return config ;
39+ } ,
40+ ( error ) => {
41+ // Do something with request error
42+ return Promise . reject ( error ) ;
43+ } ,
4144) ;
4245
4346// Add a response interceptor
4447axiosInstance . interceptors . response . use (
45- function ( response ) {
48+ ( response ) => {
4649 // Any status code that lie within the range of 2xx cause this function to trigger
4750 // Do something with response data
4851 return response ;
4952 } ,
50- function ( error ) {
53+ ( error ) => {
5154 // Any status codes that falls outside the range of 2xx cause this function to trigger
5255 // Do something with response error
5356 return Promise . reject ( error ) ;
54- }
57+ } ,
5558) ;
5659
5760export const request = < T > (
5861 config : OpenAPIConfig ,
59- options : ApiRequestOptions
62+ options : ApiRequestOptions ,
6063) : CancelablePromise < T > => {
6164 return new CancelablePromise ( ( resolve , reject , onCancel ) => {
6265 onCancel ( ( ) => source . cancel ( "The user aborted a request." ) ) ;
0 commit comments