An error in a node-red flow will generally cause an error message to be written to the debug sidebar.
However in many cases it is important that you handle errors rather than just simply logging them.
Node red provides the catch node for catching errors caused by nodes in the tab.
You can configure the catch node to catch all errors on the tab or only errors from selected nodes on the tab as shown in the screen shot below:
In addition a tab can contain multiple catch nodes, and depending on the settings a single error may be registered by several catch nodes.
There is an ignore option tick box to prevent this if needed.
The message sent by the catch node contains the error object sent by the node.
To examine this you need to look at the msg.error object coming from the inject node.
You can see from the screen shot below that the error object contains the error message and the error source.
Error and Status change
It is easy to confuse the two objects. As an example a MQTT node will issue a status change if it looses the connection and not report an error.
This is because a disconnect and connect status are both valid states and not errors.
Errors In the Function Node
The catch node can also be used to catch errors from a function node. However you can control errors in the function node by using the standard JavaScript try and catch block. See here
Related tutorials and resources:
- Using the Status Node
- Node-Red HTTP Request Node for Beginners
- Using the Node-Red Function Node- Beginners Guide
- Using the email node
- Node-red Documentation error handling