@@ -124,17 +124,30 @@ class DSHttpAdapter {
124
124
config . url += suffix ;
125
125
}
126
126
127
+ // logs the HTTP response
127
128
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 ) ;
132
147
}
133
- return data ;
134
148
} 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 ) ;
138
151
return DSUtils . Promise . reject ( data ) ;
139
152
}
140
153
}
@@ -289,4 +302,3 @@ class DSHttpAdapter {
289
302
}
290
303
291
304
module . exports = DSHttpAdapter ;
292
-
0 commit comments