Don't repeat logic for reporting stream errors

This commit is contained in:
Pasi Eronen 2017-12-13 21:28:48 +02:00 committed by Brian C
parent 4cf67b23d4
commit 70a8ee1334

View File

@ -62,14 +62,15 @@ Connection.prototype.connect = function (port, host) {
self.emit('connect')
})
this.stream.on('error', function (error) {
const reportStreamError = function (error) {
// don't raise ECONNRESET errors - they can & should be ignored
// during disconnect
if (self._ending && error.code === 'ECONNRESET') {
return
}
self.emit('error', error)
})
}
this.stream.on('error', reportStreamError)
this.stream.on('close', function () {
self.emit('end')
@ -97,15 +98,7 @@ Connection.prototype.connect = function (port, host) {
NPNProtocols: self.ssl.NPNProtocols
})
self.attachListeners(self.stream)
self.stream.on('error', function (error) {
// don't raise ECONNRESET errors - they can & should be ignored
// during disconnect
if (self._ending && error.code === 'ECONNRESET') {
return
}
self.emit('error', error)
})
self.stream.on('error', reportStreamError)
self.emit('sslconnect')
})