Skip to content

Commit

Permalink
fix: add a noop handler for the error event
Browse files Browse the repository at this point in the history
Backported from main: 15af22f
  • Loading branch information
darrachequesne committed Jun 19, 2024
1 parent f927ba2 commit d30630b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var flags = [

var emit = Emitter.prototype.emit;

function noop() {}

/**
* Interface to a `Client` for a given `Namespace`.
*
Expand All @@ -72,6 +74,9 @@ function Socket(nsp, client, query){
this.fns = [];
this.flags = {};
this._rooms = [];

// prevents crash when the socket receives an "error" event without listener
this.on('error', noop);
}

/**
Expand Down Expand Up @@ -427,12 +432,7 @@ Socket.prototype.ondisconnect = function(){
*/

Socket.prototype.onerror = function(err){
if (this.listeners('error').length) {
this.emit('error', err);
} else {
console.error('Missing error handler on `socket`.');
console.error(err.stack);
}
this.emit('error', err);
};

/**
Expand Down

0 comments on commit d30630b

Please sign in to comment.