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

Sanket Kangle
5 min readApr 26, 2022

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

Error handling scenario 5

In this scenario, we will examine the effects of an error occurring in the child flow. the source flow will call the child flow and passes the Mule event to it. An error occurs in the event processor labeled E and subsequent processors are not executed. Child flow has an on error propagate scope and calling flow has an on error continue scope present in them.

When an error happens at processor E, the Event is passed to the on error propagate scope of child flow. After the scope is executed, the error is rethrown in the calling flow without executing further processors in calling flow and handled by calling flow’s On error continue scope. further processors of the calling scope are suspended and a success message with payload is returned to the HTTP listener.

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=""xmlns:http="" xmlns=""xmlns:doc=""xmlns:xsi="" xsi:schemaLocation=""><flow name="parent-flow-5" doc:id="addb5e0f-2f13-4e1b-9f4c-870b15e8061c" ><http:listener doc:name="Listener" doc:id="f5a4a09d-7fd6-4ee1-8155-fe19a5f30c52" config-ref="HTTP_Listener_config" path="/base5"/><set-payload value='"Max Mule"' doc:name='Payload = "Max Mule"' doc:id="1b890bf5-a9ae-4ece-8e77-5a2300f7702c" /><flow-ref doc:name="Flow Reference" doc:id="91f4e45b-0fde-44dc-bf21-97ff39e06dd3" name="child-flow-5"/><set-payload doc:name='payload = "modified payload"' doc:id="57e57c9a-f6c7-4993-922d-b0a44e70c961" value='"modified payload"'/><logger level="INFO" doc:name="Logger" doc:id="83e14210-3988-4697-a63c-9a6064ea4c16" message="#[payload]"/><error-handler ><on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="aef610fb-7c4e-4b38-aba9-b5662934210c" ><set-payload value="On error continue- parent flow" doc:name='Payload = "On error continue- parent flow"' doc:id="50754cd0-e438-46cf-b5a9-5c0f65e8df4f" /><logger level="INFO" doc:name="Logger" doc:id="c3f8544f-15e9-453c-9fa6-376a190c3543" /></on-error-continue></error-handler></flow><flow name="child-flow-5" doc:id="b786fb0a-2f2f-4ee2-b358-63335e16e668" ><validation:is-null doc:name="Is null" doc:id="aec3610a-5579-4437-aa15-20bf4fcacdd3" value='#["Payload is not null"]'/><set-payload doc:name='payload = "modified child payload"' doc:id="a6c33f04-9999-4123-8c46-a567b092d45c" value='"modified child  payload"'/><logger level="INFO" doc:name="Logger" doc:id="22bf7109-1a13-4cdf-bc93-ca202a851cb9" message="#[payload]"/><error-handler ><on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="11ace283-76e1-4033-bab9-8215b5680292" ><set-payload value="On error propagate- child flow" doc:name='Payload = "On error propagate- child flow"' doc:id="e080a407-4ea4-425d-a924-03ce4f7b8ae7" /><logger level="INFO" doc:name="Logger" doc:id="307f19dc-c305-45bc-8233-75e1330f9502" /></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)

With another step, the flow reference will pass the Mule event to the child flow. (exhibit below)

When another step is taken, the error is thrown by the “is null” validation processor(exhibit below)

with the next step, the Mule event is passed is flow level error handler(exhibit below)

The payload is modified by the processor in on error propagate scope with the next step. (exhibit below)

When we come out of the error scope, the remaining flow is suspended and the Mule event is returned to the calling flow with the error object. (exhibit below)

Now, as there is an error in the calling flow, the Mule event is passed to the flow level error handler of the calling flow. (exhibit below)

The payload is modified by the processor in on error continue scope with the next step. (exhibit below)

With the next step, the payload is logged, remaining processors of the flow are suspended and a “success” response with payload is sent back to the HTTP listener, which can be seen in the response of 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