From d583c68de5dbfc79e70c5272f5c7891cb43ab5f1 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 28 May 2019 11:51:34 +0100 Subject: [PATCH] Fix error handling in Websocket broadcast function Fixes #2182 --- .../@node-red/nodes/core/io/22-websocket.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/io/22-websocket.js b/packages/node_modules/@node-red/nodes/core/io/22-websocket.js index befb8bcff..c04fd77f7 100644 --- a/packages/node_modules/@node-red/nodes/core/io/22-websocket.js +++ b/packages/node_modules/@node-red/nodes/core/io/22-websocket.js @@ -194,20 +194,23 @@ module.exports = function(RED) { } WebSocketListenerNode.prototype.broadcast = function(data) { - try { - if (this.isServer) { - for (let client in this._clients) { - if (this._clients.hasOwnProperty(client)) { + if (this.isServer) { + for (let client in this._clients) { + if (this._clients.hasOwnProperty(client)) { + try { this._clients[client].send(data); + } catch(err) { + this.warn(RED._("websocket.errors.send-error")+" "+client+" "+err.toString()) } } } - else { - this.server.send(data); - } } - catch(e) { // swallow any errors - this.warn("ws:"+i+" : "+e); + else { + try { + this.server.send(data); + } catch(err) { + this.warn(RED._("websocket.errors.send-error")+" "+err.toString()) + } } }