Skip to content

Commit

Permalink
fix(virtual-device): Fix uncaught exception when metadata is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
csuermann committed Jan 26, 2024
1 parent 801777f commit a9d4914
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion virtual-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit a9d4914

Please sign in to comment.