diff --git a/lib/WsClient.js b/lib/WsClient.js index 3052746..31d5304 100644 --- a/lib/WsClient.js +++ b/lib/WsClient.js @@ -7,6 +7,11 @@ class WsClient extends Client { this.sendUpstream(data); }); this.downstreamSocket.on('close', this.destroy.bind(this)); + this.downstreamSocket.on('error', (err) => { + // Prevent crash on error + // TODO: Log error? + this.destroy(); + }); } get type() { @@ -15,7 +20,12 @@ class WsClient extends Client { sendDownstream(data) { super.sendDownstream(data); - this.downstreamSocket.send(data); + this.downstreamSocket.send(data, (err) => { + if (err) { + // TODO: Log error? + // console.error(err); + } + }); } }