How to catch and errors from Node-RED nodes

How to catch an errors from Node-RED nodes

How to catch an errors from Node-RED nodes

In this post i will share ,how to use  Node Red  “Catch Error” node to catch  error log .

A Catch Node can be used to monitor errors that occur within nodes residing in a flow.

 

Lets Build a Catch Error Node

In order to test the  Catch Error Node, we will build a node to add up 2 Variable using a function node.

In this Function  node name as  ” Add First and third  Number ” 1 of the 2 variable are not being declared .

Thus when the Function try to add the first variable to the second variable there will be an error .

This Error will catch by the catch node

Step 1

Drag out  an inject node and configure as below

 

Step 2

Build the  Add Function  Node

Drag out the Function Node and paste the Code below inside the Function Node at the On Message Tab Area.

 

var firstNumber = flow.get(‘firstNumber’);
//var thirdNumber = flow.get(‘thirdNumber’);
// Perform addition
var total = firstNumber + thirdNumber;
// Set the result in the output message
msg.total = total;
// Return the modified message
return msg;

 

Step 3

Drag out  a Debug node configure as below.

When Done Joint All the Nodes

 

Step 4

Configure Catch Node to Monitor the Function node

When  done drag a debug node configure as below

Lastly joint the Nodes

Completed Nodes

Step 5  

Trigger  “Add”

Observe the Debug Message

 

Check Out how to use Complete Node in Node Red

 

Leave a Reply

Your email address will not be published. Required fields are marked *

5 + four =