Introduction to Flow Level Error Handling in Anypoint Platform(Mule 4) Part-2

Sanket Kangle
4 min readApr 26, 2022

Previous part: Introduction to Flow Level Error Handling in Anypoint Platform(Mule 4) Part-1

Error handling scenario 3

In this scenario, there is a flow level error handler with an On error continue scope. As the flow is executing and the error occurs at the event processor labeled E. Because of this processor P and any subsequent processors will never be executed as shown in the exhibit below.

In this scenario, the Mule event is passed to the first processor of the flow level error handler. after all processors from an on error continue scope is executed, then the error does not gets rethrown and a success message is returned. As this was the calling flow, a success message is returned to the HTTP listener as shown in the following exhibit.

Let us see this scenario with a working example.

The XML of the above flow is as follows.

<?xml version="1.0" encoding="UTF-8"?><mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation"xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"><flow name="scenario-3Flow" doc:id="cbc14607-81eb-4746-b482-69b32b80e84b" ><http:listener doc:name="Listener" doc:id="3ad80560-65e4-48a6-858e-1e174a259e41" config-ref="HTTP_Listener_config" path="/base3"/><set-payload value='"Max Mule"' doc:name='Payload = "Max Mule"' doc:id="6d5bd928-87f9-47eb-877d-441b35aa0304" /><validation:is-null doc:name="Is null" doc:id="dca8a23a-f47f-4c81-86d0-a41489820480" value='#["Payload is not null"]'/><set-payload doc:name='payload = "modified payload"' doc:id="5cf1f1c3-35f9-4805-98c1-b3fa840eaa57" value='"modified payload"'/><logger level="INFO" doc:name="Logger" doc:id="1f8d071d-ea7c-47d2-acac-9f97a464d185" message="#[payload]"/><error-handler ><on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="11344511-b003-439f-a875-d9fda370c823" ><set-payload value="On error continue- flow level error handler" doc:name='Payload = "On error continue - flow level error handler"' doc:id="5e425aae-818d-40bb-82de-fc3496197840" /><logger level="INFO" doc:name="Logger" doc:id="ffa93d73-8c49-42b6-a4a4-2cee816bfb56" message="#[payload]" /></on-error-continue></error-handler></flow></mule>

Debug the application to understand how the error is handled.

Once your application is successfully deployed, Go to Postman or Advance rest-client and send a request to the API. As seen in the exhibit below, the payload is not set yet.

Moving one step forward, the payload is set to “Max Mule” (exhibit below)

When another step is taken, the error is thrown by the “is null” validation processor

As we take another step, the Mule event is passed to the flow level error handler. (exhibit below)

The processors in on error continue scope are run and you can see the payload is now set to “on error continue-flow level error handler”

The error is also logged on the console.

The logger inside the On Error continue scope logs the payload when taken the next step and the application ends, and the success message is sent back to the HTTP listener and payload can be seen from the postman.

Give claps if you found this article useful. Stay tuned for upcoming articles.

All the images/exhibits are from the author unless given credit

Thanks for reading the article! Wanna connect with me?
Here is a link to my Linkedin Profile

--

--