diff --git a/telegrambot/nodes/out-node.js b/telegrambot/nodes/out-node.js index 389cd36..9160d4b 100644 --- a/telegrambot/nodes/out-node.js +++ b/telegrambot/nodes/out-node.js @@ -1,3 +1,20 @@ +// safely handles circular references +JSON.safeStringify = (obj, indent = 2) => { + let cache = []; + const retVal = JSON.stringify( + obj, + (key, value) => + typeof value === 'object' && value !== null + ? cache.includes(value) + ? undefined // Duplicate reference found, discard key + : cache.push(value) && value // Store value in our collection + : value, + indent + ); + cache = null; + return retVal; +}; + module.exports = function (RED) { const path = require('path'); const { pipeline } = require('stream'); @@ -124,7 +141,7 @@ module.exports = function (RED) { } if (!retry) { - let errorMessage = 'Caught exception in sender node:\r\n' + exception + '\r\nwhen processing message: \r\n' + JSON.stringify(msg); + let errorMessage = 'Caught exception in sender node:\r\n' + exception + '\r\nwhen processing message: \r\n' + JSON.safeStringify(msg); node.status({ fill: 'red',