是否可以在 Node-RED 上使用 node.error() 函数捕获对象?

Is it possible to catch an object with the node.error() function on Node-RED?

假设我有以下流程:

名为 error that we can catch but catch node doesn't see objects 的函数节点具有代码:

const object = {
   "key1": "value1", 
   "key2": "value2"
}
node.error(object, msg)

如果我 运行 它的错误将被 catch node 捕获如下:

尽管它捕获了错误,但在使用 node.error(object, msg) 时它只接受字符串而不接受对象。如果不使用 catch 节点它会工作正常......但是当我使用它时我总是会在 catch 节点中收到 [Object Object]...


节点error that we cannot catch有代码:

const object = {
   "key1": "value1", 
   "key2": "value2"
}
msg.error = object

node.error(msg)

另一方面,此节点将消息打印到调试 window,但它的消息从未被 catch node.

捕获

我想使用 catch node 捕获我在流程中作为错误发送的对象。有可能吗?或者catch node不支持捕捉对象?

样本:

[{"id":"8bdb7d23cef69c8f","type":"catch","z":"e31af9f309041c23","name":"","scope":["31ef17186604a4ff","ac478768a62912b0"],"uncaught":false,"x":1390,"y":760,"wires":[["0dce50f2ce849b21"]]},{"id":"0dce50f2ce849b21","type":"debug","z":"e31af9f309041c23","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1580,"y":760,"wires":[]},{"id":"31ef17186604a4ff","type":"function","z":"e31af9f309041c23","name":"error that we can catch but catch node doesn't see objects","currentLine":{"row":0,"column":0},"func":"const object = {\n   \"key1\": \"value1\", \n   \"key2\": \"value2\"\n}\nnode.error(object, msg)","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1730,"y":620,"wires":[]},{"id":"38ec456b9cfe72ae","type":"inject","z":"e31af9f309041c23","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1420,"y":620,"wires":[["31ef17186604a4ff"]]},{"id":"ac478768a62912b0","type":"function","z":"e31af9f309041c23","name":"error that we cannot catch","currentLine":{"row":0,"column":0},"func":"const object = {\n   \"key1\": \"value1\", \n   \"key2\": \"value2\"\n}\nmsg.error = object\n\nnode.error(msg)","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1630,"y":680,"wires":[]},{"id":"2c5f9396a10118b3","type":"inject","z":"e31af9f309041c23","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1420,"y":680,"wires":[["ac478768a62912b0"]]}]

node.error() 的第一个参数应该是字符串,而不是对象。这是因为它明确意味着是人类可读的消息

只需执行您在第二个实例中所做的操作,但包含一条包含错误的短信:

const object = {
   "key1": "value1", 
   "key2": "value2"
}
msg.error = object

node.error("Some error message",msg)