Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved some error handling.

Trying to attach error handler as soon as possible as it seems to be getting delayed.
Added a stack trace in raiseError though I'm not sure it'll do much
Improved a check when sending notifications if the socket is not available.
  • Loading branch information...
commit 4941c807c8b17510d3c6ddc6120340d71d54a5bd 1 parent 5e21b86
@argon authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 lib/connection.js
View
7 lib/connection.js
@@ -182,10 +182,10 @@ Connection.prototype.connect = function () {
}.bind(this));
this.socket.setNoDelay(false);
+ this.socket.on("error", this.errorOccurred.bind(this));
this.socket.on('data', this.handleTransmissionError.bind(this));
this.socket.on("drain", this.socketDrained.bind(this));
this.socket.on('clientError', this.errorOccurred.bind(this));
- this.socket.on("error", this.errorOccurred.bind(this));
this.socket.on("end", this.restartConnection.bind(this));
this.socket.once('close', this.restartConnection.bind(this));
}.bind(this)).fail(function (error) {
@@ -334,6 +334,9 @@ Connection.prototype.handleTransmissionError = function (data) {
*/
Connection.prototype.raiseError = function(errorCode, notification) {
debug("Raising error:", errorCode, notification);
+ if(errorCode instanceof Error) {
+ debug("Error occurred with trace:", errorCode.stack);
+ }
if (typeof this.options.errorCallback == 'function') {
this.options.errorCallback(errorCode, notification);
}
@@ -346,8 +349,8 @@ Connection.prototype.raiseError = function(errorCode, notification) {
Connection.prototype.sendNotification = function (notification) {
this.connect().then(function() {
debug("Sending notification");
- if (this.socket.socket.bufferSize !== 0 || !this.socket.writable) {
debug("Buffering notification");
+ if (!this.socket || this.socket.socket.bufferSize !== 0 || !this.socket.writable) {
this.bufferNotification(notification);
return;
}
Please sign in to comment.
Something went wrong with that request. Please try again.