11/* eslint-disable no-console */
2- import axios , { AxiosInstance , AxiosRequestConfig , AxiosError } from 'axios'
2+ import axios , { AxiosInstance , AxiosRequestConfig , AxiosError , AxiosResponse } from 'axios'
33/**
44 * GET Shifter API endpoint
55 * @param env
@@ -30,15 +30,42 @@ export class APIClientService {
3030 this . debugMode = debugMode
3131 }
3232
33+ protected _recordAxiosRequest ( url : string , path : string , config ?: AxiosRequestConfig , body ?: object ) : void {
34+ if ( ! this . debugMode ) return
35+ const request = Object . assign ( { } , {
36+ url, path, body,
37+ } )
38+ console . log ( {
39+ request,
40+ } )
41+ }
42+
43+ protected _recordAxiosResponse < Response = any > ( result : AxiosResponse < Response > ) : void {
44+ if ( ! this . debugMode ) return
45+ const _target = ( ( ) => {
46+ if ( typeof result . data !== 'object' ) {
47+ return result . data
48+ }
49+ const data = Object . assign ( { } , result . data ) as any
50+ Object . keys ( data ) . forEach ( key => {
51+ if ( / T o k e n / . test ( key ) && data [ key ] ) data [ key ] = '=== SECRET ==='
52+ } )
53+ return data
54+ } ) ( )
55+ console . log ( {
56+ result : _target ,
57+ } )
58+ }
59+
3360 public async post ( path : string , body ?: object , config ?: AxiosRequestConfig ) {
3461 return this . _post ( path , body , config )
3562 }
3663
3764 protected async _post ( path : string , body ?: object , config ?: AxiosRequestConfig ) {
3865 const url = pathJoin ( this . endpoint , path )
39- if ( this . debugMode ) console . log ( { url, path, body , config } )
66+ this . _recordAxiosRequest ( url , path , config , body )
4067 const result = await axios . post ( url , body , config )
41- if ( this . debugMode ) console . log ( { result} )
68+ this . _recordAxiosResponse ( result )
4269 return result . data
4370 }
4471
@@ -48,9 +75,9 @@ export class APIClientService {
4875
4976 protected async _get ( path : string , config ?: AxiosRequestConfig ) {
5077 const url = pathJoin ( this . endpoint , path )
51- if ( this . debugMode ) console . log ( { url, path, config} )
78+ this . _recordAxiosRequest ( url , path , config )
5279 const result = await axios . get ( url , config )
53- if ( this . debugMode ) console . log ( { result} )
80+ this . _recordAxiosResponse ( result )
5481 return result . data
5582 }
5683
0 commit comments