@@ -124,17 +124,30 @@ class DSHttpAdapter {
124124 config . url += suffix ;
125125 }
126126
127+ // logs the HTTP response
127128 function logResponse ( data ) {
128- let str = `${ start . toUTCString ( ) } - ${ data . config . method . toUpperCase ( ) } ${ data . config . url } - ${ data . status } ${ ( new Date ( ) . getTime ( ) - start . getTime ( ) ) } ms` ;
129- if ( data . status >= 200 && data . status < 300 ) {
130- if ( _this . defaults . log ) {
131- _this . defaults . log ( str , data ) ;
129+ // examine the data object
130+ if ( data instanceof Error ) {
131+ // log the Error object
132+ _this . defaults . error ( `'FAILED: ${ data . message || 'Unknown Error' } '` , data ) ;
133+ return DSUtils . Promise . reject ( data ) ;
134+ } else if ( data instanceof Object ) {
135+ let str = `${ start . toUTCString ( ) } - ${ data . config . method . toUpperCase ( ) } ${ data . config . url } - ${ data . status } ${ ( new Date ( ) . getTime ( ) - start . getTime ( ) ) } ms` ;
136+
137+ if ( data . status >= 200 && data . status < 300 ) {
138+ if ( _this . defaults . log ) {
139+ _this . defaults . log ( str , data ) ;
140+ }
141+ return data ;
142+ } else {
143+ if ( _this . defaults . error ) {
144+ _this . defaults . error ( `'FAILED: ${ str } '` , data ) ;
145+ }
146+ return DSUtils . Promise . reject ( data ) ;
132147 }
133- return data ;
134148 } else {
135- if ( _this . defaults . error ) {
136- _this . defaults . error ( `'FAILED: ${ str } ` , data ) ;
137- }
149+ // unknown type for 'data' that is not an Object or Error
150+ _this . defaults . error ( `'FAILED'` , data ) ;
138151 return DSUtils . Promise . reject ( data ) ;
139152 }
140153 }
@@ -289,4 +302,3 @@ class DSHttpAdapter {
289302}
290303
291304module . exports = DSHttpAdapter ;
292-
0 commit comments