Error Handling Inside Kumologica Subflow
The article demonstrates the general error handling and skip-on error feature inside the Kumologica subflow.
Join the DZone community and get the full member experience.Join For Free
What Is a Subflow?
A subflow in Kumologica is a defined section of a flow that is created using a Subflow In and Subflow Out node. Its purpose is to improve the reusability of code and enhance the readability of the overall flow. The Subflow node can be used to call the subflow from any point in the flow.
Once a Subflow In node is added to the canvas, its name will appear in the dropdown list of the Subflow node. Each subflow execution operates within its own context and does not modify the payload, variables, or message properties.
Error Handling Approaches
When it comes to subflows, there are two ways to handle errors. The first approach involves catching the mistake, handling it, and then abruptly stopping any further processing.
Alternatively, the second approach is to catch the error and skip to the next processing block without stopping the flow. The second approach is mostly used when you are using the subflow inside a for loop for iteration. Whenever an error occurs inside the loop the catch node instead of wiring to an EvenListener End node will be wired to the For-Loop end node. By doing this the iteration is automatically skipped to the next iteration without doing any other processing associated with the for-loop processing block. Eg: In the below image Node 3 is skipped when thrown at Node 2.
1. Node.JS installation (node version: 16.14.0, npm version: 8.3.1)
1. Install the latest Kumologica designer (3.1.0).
In this article, I will implement a simple Kumologica flow demonstrating both error-handling approaches. Following is the flow which I will be using for this demonstration.
We will first build a subflow that is invoked from the main flow.
1. Click on the Navigator view in the designer and create a new flow by providing a name samplesubflow.
2. Drag and drop Subflow In and Subflow Out nodes from the pallet to the designer.
3. Add an HTTP Req node to the canvas and wire to the Subflow In node.
4. Wire the HTTP Req node output to Subflow out node.
Provide the configuration for the HTTP Req node as given below.
Method : GET URL : http://httpbin.org/wrongip Return : a UTF-8 string
5. Now ensure that the main flow (Main flow image above) subflow invoke node is having the Subflow selected.
6. Add a test case flow as given below to execute the flow to see if an error is generated. The test case flow will have an HTTP TestCase node wired directly to the TestCaseEnd node.
On running the test case from the test case runner option you could see the 404 error response as the HTTP endpoint we provided was incorrect.
Stop on Error
1. Now let's capture the error thrown by the HTTP Req node. For this, we will configure a catch node as given below.
In the above screen, you can see that the HTTP req node is selected for catching all the errors generated by that node.
2. Wire the Catch node to the Event Listener End node for sending the error response back to the client.
On running the test case we can see that error is handled and the custom response is returned by the flow. The flow is abruptly stopped
Skip on error
1. Now we try implementing skip-on an error by removing the Evenlistener End from the earlier built flow.
2. Once the Evenlistner End node is removed, we will wire the catch node directly to the Subflow Out node.
On running the test case we can see that error is handled and skipped which ultimately completes the flow successfully.
Hope the article helped you in understanding and effectively use error handling inside a subflow for the appropriate use case. I will come up with a different topic for my next article. Till then stay tuned.
Opinions expressed by DZone contributors are their own.
Step Into Serverless Computing
Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
Top 10 Pillars of Zero Trust Networks
Integrate Cucumber in Playwright With Java