From a22b856494a8c599c9d1acea4edb8a210c1a12d1 Mon Sep 17 00:00:00 2001 From: Pascal Date: Sat, 20 Jan 2018 09:05:07 +0100 Subject: [PATCH] fix(WebSocketConnection): make errors in event handlers throw again The error from something like client.on('ready', () => undefined.f); would just be emitted as debug event instead of being thrown. Simply moving the emitting part out of the try catch again solves this. --- src/client/websocket/WebSocketConnection.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/websocket/WebSocketConnection.js b/src/client/websocket/WebSocketConnection.js index 4e3835ef0..5e07b1a69 100644 --- a/src/client/websocket/WebSocketConnection.js +++ b/src/client/websocket/WebSocketConnection.js @@ -269,13 +269,15 @@ class WebSocketConnection extends EventEmitter { this.inflate.push(data, flush && zlib.Z_SYNC_FLUSH); if (!flush) return; + let packet; try { - const packet = WebSocket.unpack(this.inflate.result); - this.onPacket(packet); - if (this.client.listenerCount('raw')) this.client.emit('raw', packet); + packet = WebSocket.unpack(this.inflate.result); } catch (err) { this.client.emit('debug', err); + return; } + this.onPacket(packet); + if (this.client.listenerCount('raw')) this.client.emit('raw', packet); } /**