Skip to content

Commit

Permalink
Adding error handling inside stream end callback (#3967)
Browse files Browse the repository at this point in the history
* Adding error handling inside end callback  for response streams

* Updating error handling in stream end callback

* Update http.js

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
djs113 and jasonsaayman committed Dec 23, 2021
1 parent 4fbf61d commit ea0d9c6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/adapters/http.js
Expand Up @@ -297,15 +297,18 @@ module.exports = function httpAdapter(config) {
});

stream.on('end', function handleStreamEnd() {
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') {
responseData = responseData.toString(config.responseEncoding);
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
responseData = utils.stripBOM(responseData);
try {
var responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') {
responseData = responseData.toString(config.responseEncoding);
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
responseData = utils.stripBOM(responseData);
}
}
response.data = responseData;
} catch (err) {
reject(enhanceError(err, config, err.code, response.request, response));
}

response.data = responseData;
settle(resolve, reject, response);
});
}
Expand Down

0 comments on commit ea0d9c6

Please sign in to comment.