Need help taking this message apart and making a new one

This is the error message I get:

{"_msgid":"95a5f34b.89b7f","topic":"ERROR_REPORT/BedPi/Logging/","error":{"message":"ReferenceError: a is not defined (line 1, col 19)","source":{"id":"f15d59f6.b745","type":"function","name":"This will throw an error","count":1}},"_error":{},"time":"2020-05-20 19:41:31","payload":"Cause an error"}

I am wanting to create a message showing the error which can be written to a text file - human readable.

This is the code I have so far:

let when = msg.time;
let who = msg.topic;
let what = msg.error;
let where = msg.error.source;

node.warn("What " + what);
node.warn("Where " + where);


msg.payload = "When " + when + "\nWho " + who + "\nWhat " + what + "\nWhere " + where;

return msg;

But I get this as the output:

When 2020-05-20 19:41:31Who ERROR_REPORT/BedPi/ERROR_REPORT/BedPi/Logging/What [object Object]Where [object Object]

I'm messing up with the objects. I know.

This is a big (huge) re-write of a lot of code as I finally discovered that what I had doesn't work.

I'm stupid.

Worked it out with this:

let when_ = msg.time;
let who_ = msg.topic;
let what_ = msg.error.message;
let where_ = msg.error.source.id;

node.warn("What " + what_);
node.warn("Where " + where_);


msg.payload = "When " + when_ + "\nWho " + who_ + "\nWhat " + what_ + "\nWhere " + where_;

return msg;

Are you using node-red-contrib-flogger?

You can simply pass an object to it & it'll add the whole msg object (as JSON) into a file - no fuss, no muss.

Never heard of that.

(Dumb question) would it be better for me for this single use?

I have since added more stuff to the code to again make it more readable.
But not to the point of rocket science.

I may have a peep at the node, but was just wondering about its overheads.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.