简体   繁体   English

来自不引发标准异常的节点的 Node-RED 处理错误

[英]Node-RED Handle error from node that throws no standardexception

I want to use the Pushover Node to send notifications.我想使用 Pushover 节点发送通知。 I'm already using it via curl for some time and very seldom some messages aren't sent.我已经通过 curl 使用它一段时间了,很少有一些消息没有发送。 Thats why I have in bash这就是为什么我在 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.捕获错误,然后通过 email 发送消息。

Now I want to do something similiar in Node-Red.现在我想在 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出于测试目的,如果通过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在 node-red-log 我看到

18 May 13:46:24 - [error] [pushover:252a17dc.1239d8] Error: connect ECONNREFUSED 104.20.125.71:443 5 月 18 日 13:46:24 - [错误] [pushover:252a17dc.1239d8] 错误:连接 ECONNREFUSED 104.20.125.71:443

Now look at this Node-RED flow现在看看这个 Node-RED 流程

Node-RED 流

The error is displayed in the debug window and comes from pushover node.该错误显示在调试 window 中,并且来自 pushover 节点。 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/ catch 节点没有捕捉到预期,显然是因为 pushover 没有使用异常框架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?但是在这种情况下,我如何对 Node-RED 中的这个错误做出反应以做其他事情呢?

I'll guess from looking at the source that the error is coming from line 103 of the 57-pushover.js file.我会从查看源代码中猜测错误来自57-pushover.js文件的第103行。

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.此行上对node.error()的调用不会推送传入的msg object,因此它不会传递给 catch 节点。 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. node.error() function 有 2 个签名,第一个只取错误消息,第二个取错误消息和传入的msg object,只有第二个转发错误和msg ZA8CFDE6331BD49EB2AC96F86 传递给 catch1 节点。

Please feel free to submit a pull request to update this node.请随时提交拉取请求以更新此节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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