Skip to content

Commit 70a8ee1

Browse files
pasieronenbrianc
authored andcommitted
Don't repeat logic for reporting stream errors
1 parent 4cf67b2 commit 70a8ee1

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/connection.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ Connection.prototype.connect = function (port, host) {
6262
self.emit('connect')
6363
})
6464

65-
this.stream.on('error', function (error) {
65+
const reportStreamError = function (error) {
6666
// don't raise ECONNRESET errors - they can & should be ignored
6767
// during disconnect
6868
if (self._ending && error.code === 'ECONNRESET') {
6969
return
7070
}
7171
self.emit('error', error)
72-
})
72+
}
73+
this.stream.on('error', reportStreamError)
7374

7475
this.stream.on('close', function () {
7576
self.emit('end')
@@ -97,15 +98,7 @@ Connection.prototype.connect = function (port, host) {
9798
NPNProtocols: self.ssl.NPNProtocols
9899
})
99100
self.attachListeners(self.stream)
100-
101-
self.stream.on('error', function (error) {
102-
// don't raise ECONNRESET errors - they can & should be ignored
103-
// during disconnect
104-
if (self._ending && error.code === 'ECONNRESET') {
105-
return
106-
}
107-
self.emit('error', error)
108-
})
101+
self.stream.on('error', reportStreamError)
109102

110103
self.emit('sslconnect')
111104
})

0 commit comments

Comments
 (0)