Skip to content

Commit 1e87298

Browse files
committed
Modify handling of err.res
1 parent d134f73 commit 1e87298

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/requester/requester.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,25 @@ class Requester extends EventEmitter {
439439
// prepare history from request debug data
440440
var history = getExecutionHistory(debug),
441441
responseTime,
442-
response,
443-
errorHasUsableResponse = false;
442+
response;
444443

445-
if (err && err.res && err.res.body && Buffer.isBuffer(err.res.body)) {
446-
errorHasUsableResponse = true;
447-
resBody = err.res.body;
448-
}
449-
450-
if (err && !errorHasUsableResponse) {
444+
if (err && !err.res) {
451445
// bubble up http errors
452446
// @todo - Should we send an empty sdk Response here?
453447
//
454448
// Sending `history` object even in case of error
455449
return onEnd(err, undefined, history);
456450
}
457451

452+
// If the error has a response attached, use it to populate the response instead of treating
453+
// it as a crash.
454+
if (err && err.res) {
455+
res = err.res;
456+
457+
if (Buffer.isBuffer(err.res.body)) {
458+
resBody = err.res.body;
459+
}
460+
}
458461

459462
// Calculate the time taken for us to get the response.
460463
responseTime = Date.now() - startTime;

0 commit comments

Comments
 (0)