@@ -21,6 +21,7 @@ import https = require('https');
2121import querystring = require( 'querystring' ) ;
2222import { PassThrough as readableStream } from 'stream' ;
2323import { buildRequestFileObject , getMissingParams , isEmptyObject , isFileData , isFileWithMetadata } from './helper' ;
24+ import logger from './logger' ;
2425
2526const isBrowser = typeof window === 'object' ;
2627const globalTransactionId = 'x-global-transaction-id' ;
@@ -67,42 +68,42 @@ export class RequestWrapper {
6768 this . axiosInstance = axios . create ( axiosConfig ) ;
6869
6970 // set debug interceptors
70- if ( process . env . NODE_DEBUG === 'axios' ) {
71+ if ( process . env . NODE_DEBUG === 'axios' || process . env . DEBUG ) {
7172 this . axiosInstance . interceptors . request . use ( config => {
72- console . debug ( 'Request:' ) ;
73+ logger . debug ( 'Request:' ) ;
7374 try {
74- console . debug ( JSON . stringify ( config , null , 2 ) ) ;
75+ logger . debug ( JSON . stringify ( config , null , 2 ) ) ;
7576 } catch {
76- console . debug ( config )
77+ logger . error ( config )
7778 }
7879
7980 return config ;
8081 } , error => {
81- console . debug ( 'Error:' ) ;
82+ logger . error ( 'Error: ' ) ;
8283 try {
83- console . debug ( JSON . stringify ( error , null , 2 ) ) ;
84+ logger . error ( JSON . stringify ( error , null , 2 ) ) ;
8485 } catch {
85- console . debug ( error ) ;
86+ logger . error ( error ) ;
8687 }
8788
8889 return Promise . reject ( error ) ;
8990 } ) ;
9091
9192 this . axiosInstance . interceptors . response . use ( response => {
92- console . debug ( 'Response:' ) ;
93+ logger . debug ( 'Response:' ) ;
9394 try {
94- console . debug ( JSON . stringify ( response , null , 2 ) ) ;
95+ logger . debug ( JSON . stringify ( response , null , 2 ) ) ;
9596 } catch {
96- console . debug ( response )
97+ logger . error ( response ) ;
9798 }
9899
99100 return response ;
100101 } , error => {
101- console . debug ( 'Error:' ) ;
102+ logger . error ( 'Error: ' ) ;
102103 try {
103- console . debug ( JSON . stringify ( error , null , 2 ) ) ;
104+ logger . error ( JSON . stringify ( error , null , 2 ) ) ;
104105 } catch {
105- console . debug ( error ) ;
106+ logger . error ( error ) ;
106107 }
107108
108109 return Promise . reject ( error ) ;
@@ -259,6 +260,7 @@ export class RequestWrapper {
259260 // ignore the error, use the object, and tack on a warning
260261 errorBody = axiosError . data ;
261262 errorBody . warning = 'Body contains circular reference' ;
263+ logger . error ( `Failed to stringify axiosError: ${ e } ` ) ;
262264 }
263265
264266 error . body = errorBody ;
@@ -385,5 +387,6 @@ function parseServiceErrorMessage(response: any): string | undefined {
385387 message = response . errorMessage ;
386388 }
387389
390+ logger . info ( `Parsing service error message: ${ message } ` ) ;
388391 return message ;
389392}
0 commit comments