From a9d4914dd5dcf7fcc67c03fd16100d8713152c29 Mon Sep 17 00:00:00 2001 From: Cornelius Suermann Date: Fri, 26 Jan 2024 18:49:48 +0100 Subject: [PATCH] fix(virtual-device): Fix uncaught exception when metadata is not set --- virtual-device.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/virtual-device.js b/virtual-device.js index 66342d0..a4bca10 100644 --- a/virtual-device.js +++ b/virtual-device.js @@ -51,10 +51,18 @@ module.exports = function (RED) { friendlyName: config.name, }) + let metadata + + try { + metadata = JSON.parse(config.metadata ?? '{}') + } catch (e) { + metadata = {} + } + if (Object.keys(payload).length > 0) { const msg = { topic: topic ? topic : config.topic, - metadata: JSON.parse(config.metadata ?? '{}'), + metadata, payload, }