diff --git a/lib/socket.js b/lib/socket.js index bfdd77e856..cb7ba4123e 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -49,6 +49,8 @@ var flags = [ var emit = Emitter.prototype.emit; +function noop() {} + /** * Interface to a `Client` for a given `Namespace`. * @@ -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); } /** @@ -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); }; /**