简体   繁体   中英

Node-RED Handle error from node that throws no standardexception

I want to use the Pushover Node to send notifications. I'm already using it via curl for some time and very seldom some messages aren't sent. Thats why I have in bash

echo "$curlOutput" | grep -qP '{"status":1' 
if [ ! $? -eq 0 ] 
then
    echo "$2" | mail --append "Content-Type: text/plain; charset=UTF-8" -s "$1" name@company.com
fi

to capture the error and then send the message via email.

Now I want to do something similiar in Node-Red. For testing purposes if simulated a network error via sudo iptables -A OUTPUT -d 104.20.0.0/16 -m comment --comment "Pushovertest" -j REJECT

That successfully blocks. In node-red-log I see

18 May 13:46:24 - [error] [pushover:252a17dc.1239d8] Error: connect ECONNREFUSED 104.20.125.71:443

Now look at this Node-RED flow

Node-RED 流

The error is displayed in the debug window and comes from pushover node. The catch node doesn't catch the expection, obviously because pushover doesn't use the exception framework https://developer.ibm.com/recipes/tutorials/nodered-exception-handling-framework/

First test passed: There is an error logged. But how can I react to this error within Node-RED to do something else in this case?

I'll guess from looking at the source that the error is coming from line 103 of the 57-pushover.js file.

The call to node.error() on this line is not pushing the incoming msg object so it won't be passed to the catch node. There are 2 signatures for the node.error() function, the first just takes the error message, the second takes the error message and the incoming msg object, only the second forwards the error and msg object is passed to the catch node.

Please feel free to submit a pull request to update this node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM