From 3e58696c07161ef84c6b12aeb7e03d271563dcb9 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 2 Feb 2011 15:37:48 -0800 Subject: [PATCH] TLS: Simplify error handling --- lib/tls.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 7bd8cafa6..b7db6efc4 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -196,11 +196,7 @@ CryptoStream.prototype._push = function() { chunkBytes = this._pusher(pool, bytesRead, pool.length - bytesRead); if (this.pair._ssl && this.pair._ssl.error) { - if (this.pair._secureEstablished) { - this.pair._error(); - } else { - this.pair._destroy(); - } + this.pair._error(); return; } @@ -277,11 +273,7 @@ CryptoStream.prototype._pull = function() { var rv = this._puller(tmp); if (this.pair._ssl && this.pair._ssl.error) { - if (this.pair._secureEstablished) { - this.pair._error(); - } else { - this.pair._destroy(); - } + this.pair._error(); return; } @@ -500,16 +492,20 @@ SecurePair.prototype._destroy = function() { SecurePair.prototype._error = function() { - var err = this._ssl.error; - this._ssl.error = null; - - if (this._isServer && - this._rejectUnauthorized && - /peer did not return a certificate/.test(err.message)) { - // Not really an error. + if (!this._secureEstablished) { this._destroy(); } else { - this.cleartext.emit('error', err); + var err = this._ssl.error; + this._ssl.error = null; + + if (this._isServer && + this._rejectUnauthorized && + /peer did not return a certificate/.test(err.message)) { + // Not really an error. + this._destroy(); + } else { + this.cleartext.emit('error', err); + } } }; -- 2.34.1