Skip to content

Commit

Permalink
Adding aborted event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
koh110 committed Aug 16, 2021
1 parent 7a8907a commit 3b7af99
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -47,7 +47,9 @@ module.exports = function httpAdapter(config) {
var resolve = function resolve(value) {
resolvePromise(value);
};
var rejected = false;
var reject = function reject(value) {
rejected = true;
rejectPromise(value);
};
var data = config.data;
Expand Down Expand Up @@ -251,6 +253,14 @@ module.exports = function httpAdapter(config) {
}
});

stream.on('aborted', function handlerStreamAborted() {
if (rejected) {
return;
}
stream.destroy();
reject(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest));
});

stream.on('error', function handleStreamError(err) {
if (req.aborted) return;
reject(enhanceError(err, config, null, lastRequest));
Expand Down

0 comments on commit 3b7af99

Please sign in to comment.