From d2218807cf1881b2dde5b7cfe20146fcd85d7e97 Mon Sep 17 00:00:00 2001 From: Marco Stoffel Date: Fri, 20 Sep 2024 11:51:48 +0200 Subject: [PATCH] fix: catch malformated message --- .../src/nodes/notification/notification.js | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/node-red-contrib-c8y-client/src/nodes/notification/notification.js b/node-red-contrib-c8y-client/src/nodes/notification/notification.js index dd74c3e..15404fb 100644 --- a/node-red-contrib-c8y-client/src/nodes/notification/notification.js +++ b/node-red-contrib-c8y-client/src/nodes/notification/notification.js @@ -184,14 +184,22 @@ module.exports = function (RED) { node.debug( `New Notification id: ${id} source: ${source} operation: ${operation} \n payload: ${payload}` ); - const msg = { - payload: { - id: id, - source: source, - operation: operation, - message: JSON.parse(payload), - }, - }; + let msg; + try { + msg = { + payload: { + id: id, + source: source, + operation: operation, + message: JSON.parse(payload), + }, + }; + } catch (error) { + node.error( + `[ws error] parsing payload ${error}` + ); + return; + } // Ack message try { node.socket.send(id);