Hi There!
I'm wondering what is the best way of capturing errors that are raised within the flow of a link-call?
Example flow:
[{"id":"2bd6810d.e22ece","type":"catch","z":"da728ee9d651fde8","name":"","scope":["2c94a22c.91012e"],"uncaught":false,"x":791,"y":539,"wires":[["ea01375bb63004ca"]]},{"id":"2c94a22c.91012e","type":"function","z":"da728ee9d651fde8","name":"Throw Error","func":"node.error(\"an example error\", msg); ","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":805,"y":454,"wires":[["ea01375bb63004ca"]]},{"id":"72517b3dadec43f9","type":"link in","z":"da728ee9d651fde8","name":"link in 2","links":[],"x":518,"y":370,"wires":[["2c94a22c.91012e"]]},{"id":"ea01375bb63004ca","type":"link out","z":"da728ee9d651fde8","name":"link out 79","mode":"return","links":[],"x":1094,"y":337,"wires":[]},{"id":"a957d4a801015562","type":"link call","z":"da728ee9d651fde8","name":"","links":["72517b3dadec43f9"],"linkType":"static","timeout":"4","x":1366,"y":666,"wires":[["f303e4920a752c2c"]]},{"id":"a1324180ccb5429d","type":"inject","z":"da728ee9d651fde8","name":"Trigger error","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1161,"y":633,"wires":[["a957d4a801015562"]]},{"id":"eee84a44f3b6bb69","type":"catch","z":"da728ee9d651fde8","name":"","scope":["a957d4a801015562","f303e4920a752c2c"],"uncaught":false,"x":1378,"y":733,"wires":[["1d0da1cc549ad8f3"]]},{"id":"1d0da1cc549ad8f3","type":"debug","z":"da728ee9d651fde8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1774,"y":659,"wires":[]},{"id":"495237ede246b15d","type":"debug","z":"da728ee9d651fde8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1801,"y":467,"wires":[]},{"id":"f303e4920a752c2c","type":"function","z":"da728ee9d651fde8","name":"detect error","func":"if ( msg.error ) {\n node.error(\"error detected\", msg)\n} else {\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1565,"y":566,"wires":[["495237ede246b15d"]]}]
The link in 2
link call node calls the Throw Error
function which throws the error. The error is normally captured by the catch: 1
catch node and passed out by the link-out node to which it is connected. Otherwise the error does not find its way back to the link call node. That is, if the error thrown by the Throw Error
function isn't caught, it disappears into the ether and the link call
node times out.
But I want the original error thrown by the function node Throw Error
so I've caught it and passed it out. Now I would like the link in 2
link-call node to re-throw the error but it doesn't. Instead I've added a detect error
function that throws an error if the error property is set on the msg, its code:
if ( msg.error ) {
node.error("error detected", msg)
} else {
return msg;
}
Using this setup, I come out at the catch: 2
catch node and over to the (bottom) msg
debug node. That's what I want. Is there an easier way to do this? I don't really want to have a detect error
function node after all my link-call nodes.
What I want is something like this:
With the same affect that I come out at the bottom debug node... is that possible with some magic settings or is there no way of doing it? I understand that the link out node isn't reached when the error is raised but if I add the catch that is connected to the link out node, then the msg (containing the error) is handled as a normal msg and the top debug node is reached, i.e., I would wish that the link-call node detects the error property on the message and throws an error as a result.
My goal is to get the original error object and not a timeout
error that will be raised by the link-call if the link-out node isn't reached ... which is the case presently.
Sorry if this has been answered elsewhere ...
Cheers!
Edit: just noticed that if the Throw Error
function node has a node.status({...})
update, that isn't passed to the link-call node either. It's shown on the Throw Error
function node but not on the calling link-call node. Ideally each link-call node would be assigned the status that the original node generated but if the flow consists of many nodes, all with their own status updates, which would be passed to the link-call node? Hm.