@@ -21,6 +21,7 @@ import https = require('https');
21
21
import querystring = require( 'querystring' ) ;
22
22
import { PassThrough as readableStream } from 'stream' ;
23
23
import { buildRequestFileObject , getMissingParams , isEmptyObject , isFileData , isFileWithMetadata } from './helper' ;
24
+ import logger from './logger' ;
24
25
25
26
const isBrowser = typeof window === 'object' ;
26
27
const globalTransactionId = 'x-global-transaction-id' ;
@@ -67,42 +68,42 @@ export class RequestWrapper {
67
68
this . axiosInstance = axios . create ( axiosConfig ) ;
68
69
69
70
// set debug interceptors
70
- if ( process . env . NODE_DEBUG === 'axios' ) {
71
+ if ( process . env . NODE_DEBUG === 'axios' || process . env . DEBUG ) {
71
72
this . axiosInstance . interceptors . request . use ( config => {
72
- console . debug ( 'Request:' ) ;
73
+ logger . debug ( 'Request:' ) ;
73
74
try {
74
- console . debug ( JSON . stringify ( config , null , 2 ) ) ;
75
+ logger . debug ( JSON . stringify ( config , null , 2 ) ) ;
75
76
} catch {
76
- console . debug ( config )
77
+ logger . error ( config )
77
78
}
78
79
79
80
return config ;
80
81
} , error => {
81
- console . debug ( 'Error:' ) ;
82
+ logger . error ( 'Error: ' ) ;
82
83
try {
83
- console . debug ( JSON . stringify ( error , null , 2 ) ) ;
84
+ logger . error ( JSON . stringify ( error , null , 2 ) ) ;
84
85
} catch {
85
- console . debug ( error ) ;
86
+ logger . error ( error ) ;
86
87
}
87
88
88
89
return Promise . reject ( error ) ;
89
90
} ) ;
90
91
91
92
this . axiosInstance . interceptors . response . use ( response => {
92
- console . debug ( 'Response:' ) ;
93
+ logger . debug ( 'Response:' ) ;
93
94
try {
94
- console . debug ( JSON . stringify ( response , null , 2 ) ) ;
95
+ logger . debug ( JSON . stringify ( response , null , 2 ) ) ;
95
96
} catch {
96
- console . debug ( response )
97
+ logger . error ( response ) ;
97
98
}
98
99
99
100
return response ;
100
101
} , error => {
101
- console . debug ( 'Error:' ) ;
102
+ logger . error ( 'Error: ' ) ;
102
103
try {
103
- console . debug ( JSON . stringify ( error , null , 2 ) ) ;
104
+ logger . error ( JSON . stringify ( error , null , 2 ) ) ;
104
105
} catch {
105
- console . debug ( error ) ;
106
+ logger . error ( error ) ;
106
107
}
107
108
108
109
return Promise . reject ( error ) ;
@@ -259,6 +260,7 @@ export class RequestWrapper {
259
260
// ignore the error, use the object, and tack on a warning
260
261
errorBody = axiosError . data ;
261
262
errorBody . warning = 'Body contains circular reference' ;
263
+ logger . error ( `Failed to stringify axiosError: ${ e } ` ) ;
262
264
}
263
265
264
266
error . body = errorBody ;
@@ -385,5 +387,6 @@ function parseServiceErrorMessage(response: any): string | undefined {
385
387
message = response . errorMessage ;
386
388
}
387
389
390
+ logger . info ( `Parsing service error message: ${ message } ` ) ;
388
391
return message ;
389
392
}
0 commit comments