Detect error in msg.payload

Hi!
My heatpump is occasionally busy. The node (luxtronic) then reports (according to Debug) an error

msg.payload : error
{ name: "Error", message: "heatpump busy - state: 1", stack: "Error: heatpump busy - state: …" }

instead of

msg.payload : Object
{ values: object, parameters: object, additional: object }

What is the preferrred way to find out if an error occured. I look now if payload has the key values. This works, but it feels … kind of indirect.

Cheers, Uwe

Use a Catch node linked to the luxtronic node and see if that picks it up. If the node is well behaved it should go to the Catch node and not to the normal output.

A catch node is a good idea, particularly if I wanted to react and do something special in that case.

However, this heat pump error condition is quite "normal". Then I just want to "filter" this out in the normal flow using a switch-node.

I thought and asked the best buddy w/ "instance" and the like, but my did tries not work. E.g. JSONATA $type(payload) = "error" did not work for me.

But msg.payload 'has key' values correctly fails in that 'error' case. So I decided this is a valid condition to continue the flow and stop it otherwise.

But as I said: This is kind of fragile, since it depends on the underlying format (not that fragile, since the Luxtronic node will probably not change its format).

I would like to implement something like

switch node: 
   if msg.payload is a 'proper' object and not resulting from an 'error'  
       exit 1
   else
      exit 2

Cheers, Uwe

Does the catch node catch it?

If it does, does that stop it appearing on the normal output?

You should be able to filter using a switch node, using msg.payload.name != "Error".
e.g.

[{"id":"6b9ba61b9e7dcb63","type":"inject","z":"613df62afc8a16bf","name":"error","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":" { \"name\": \"Error\", \"message\": \"heatpump busy \"}","payloadType":"json","x":110,"y":120,"wires":[["068fa6d5ef6c12c0"]]},{"id":"068fa6d5ef6c12c0","type":"switch","z":"613df62afc8a16bf","name":"","property":"payload.name","propertyType":"msg","rules":[{"t":"neq","v":"Error","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":140,"wires":[["8630151819cc7629"]]},{"id":"7618f6a801cff71c","type":"inject","z":"613df62afc8a16bf","name":"values","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"values\":{ \"name\": \"Error\", \"message\": \"heatpump busy \"}}","payloadType":"json","x":110,"y":200,"wires":[["068fa6d5ef6c12c0"]]},{"id":"8630151819cc7629","type":"debug","z":"613df62afc8a16bf","name":"debug 2589","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":140,"wires":[]}]

No, catch does not catch the luxtronic-node error.

Great! I went for $exists(payload.name) and payload.name = "Error" and this does the job.

I don't think JSONata needs to be used here.
Just msg.payload. name != "Error" in the switch node.
If payload.name does not exist it would be undefined, therefore !=.

But if it works for you, then what ever you wish to use is OK.

1 Like