Skip to content

Commit 79376fd

Browse files
authored
fix: treat aborts the same as before node 16 (request#7)
1 parent 484dd53 commit 79376fd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

request.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,14 @@ Request.prototype.onRequestResponse = function (response) {
10701070
self.emit('end', chunk)
10711071
})
10721072
responseContent.on('error', function (error) {
1073+
if (error.code === 'ECONNRESET' && error.message === 'aborted' && self.listenerCount('error') === 0) {
1074+
// Node 16 causes aborts to emit errors if there is an error listener.
1075+
// Without this short-circuit, it will cause unhandled exceptions since
1076+
// there is not always an `error` listener on `self`, but there will
1077+
// always be an `error` listener on `responseContent`.
1078+
// @see https://github.com/nodejs/node/pull/33172
1079+
return
1080+
}
10731081
self.emit('error', error)
10741082
})
10751083
responseContent.on('close', function () { self.emit('close') })

0 commit comments

Comments
 (0)