Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion telegrambot/nodes/out-node.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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',
Expand Down
Loading