From 70a8ee1334214ef3e13057217522a1d5de3dbc2d Mon Sep 17 00:00:00 2001 From: Pasi Eronen Date: Wed, 13 Dec 2017 21:28:48 +0200 Subject: [PATCH] Don't repeat logic for reporting stream errors --- lib/connection.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 61f2562f..7b7a8abf 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -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') })