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

Sanket Kangle
4 min readApr 26, 2022

Prerequisite for the article: Introduction to Error Handling in Anypoint Studio(Mule 4)

Error handling scenario 2

In this scenario, there is a flow level error handler with an On error propagate 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 propagate scope are executed, the error gets rethrown. As this flow was the calling flow, the error response is returned to the HTTP listener as shown in the exhibit below.

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.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd"><flow name="scenario-2-Flow" doc:id="d929ba40-7105-4395-9acd-a6e253b76d8b" ><http:listener doc:name="Listener" doc:id="f44b5859-7c6c-44a9-aef0-3de47d4e29d4" config-ref="HTTP_Listener_config" path="/base1"/><set-payload value='"Max Mule"' doc:name='Payload = "Max Mule"' doc:id="b4293699-be73-408d-9358-70de0a11ce57" /><validation:is-null doc:name="Is null" doc:id="9dfc55f1-b89b-4e77-b0bc-91c813437225" value='#["Payload is not null"]'/><set-payload doc:name='payload = "modified payload"' doc:id="4ac7c9fd-0a4c-4a73-a921-52fb3b1a28ce" value='"modified payload"'/><logger level="INFO" doc:name="Logger" doc:id="90b0a612-d2d5-4088-97e7-a6c104d8fa3f" message="#[payload]"/><error-handler ><on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="de731544-ba47-48e0-9fab-b22c939be1ea" ><set-payload value="On error propagate- flow level error handler" doc:name='Payload = "On error propagate- flow level error handler"' doc:id="399d1919-372a-4529-aafe-a9e917aa78ea" /><logger level="INFO" doc:name="Logger" doc:id="9f6ba407-e187-4b29-9486-9dfe09fabfa9" message="#[payload]"/></on-error-propagate></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 through the flow level error handler.(exhibit below)

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

The error is also logged on the console.

The logger inside the On Error propagate scope logs the payload when taken the next step and the application ends, and the error message is sent back to the HTTP listener and 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

--

--