Skip to content

Commit d30630b

Browse files
fix: add a noop handler for the error event
Backported from main: 15af22f
1 parent f927ba2 commit d30630b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/socket.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var flags = [
4949

5050
var emit = Emitter.prototype.emit;
5151

52+
function noop() {}
53+
5254
/**
5355
* Interface to a `Client` for a given `Namespace`.
5456
*
@@ -72,6 +74,9 @@ function Socket(nsp, client, query){
7274
this.fns = [];
7375
this.flags = {};
7476
this._rooms = [];
77+
78+
// prevents crash when the socket receives an "error" event without listener
79+
this.on('error', noop);
7580
}
7681

7782
/**
@@ -427,12 +432,7 @@ Socket.prototype.ondisconnect = function(){
427432
*/
428433

429434
Socket.prototype.onerror = function(err){
430-
if (this.listeners('error').length) {
431-
this.emit('error', err);
432-
} else {
433-
console.error('Missing error handler on `socket`.');
434-
console.error(err.stack);
435-
}
435+
this.emit('error', err);
436436
};
437437

438438
/**

0 commit comments

Comments
 (0)