Error Handling in Mule 4 | Mule 4 Exception Handling Types

Error Handling in mule 4

Error handling in mule 4 is done by:
1. Error Handler
2. On error continue
3. On error propagate
4. Raise error

First Scenario is handling of error by: On error continue

On error continue settings:

On error continue handles the error and control moves to next component and gives 200 success response code. In this component, control do not move to message source after error occurs.

Second scenario is error handling by: on error propagate

On error propagate settings:

On error propagate logs the error if it occurs and gives error code and control moves to message source.

Third scenario is: error handler.
We configure error handler to global error handler. Global error handler is common to all flows in an application.
To configure it, go to:
 global elements -> create -> global configurations-> configurations

Flow of global error handler:

We can configure on error continue or on error propagate in it.

Fourth scenario is: Raise error.
It throws an error with the specific type and description.

Raise error settings:

Handling of error takes place at three levels:
1. Processor level
2. Flow level
3. Application level

XML project code:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="" xmlns:http=""
     xmlns:doc="" xmlns:xsi="" xsi:schemaLocation="">
     <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="90060ac9-ab94-4e7d-8779-5edb29635514" >
          <http:listener-connection host="" port="8085" />
     <configuration doc:name="Configuration" doc:id="57a21529-8e04-4148-8d98-1e840341be1d" defaultErrorHandler-ref="test_error_handlingError_Handler" />
     <flow name="test_error_handlingFlow" doc:id="85132160-a53f-4b94-84e8-58f28d370212" >
          <http:listener doc:name="Listener" doc:id="6c72fd63-e2e2-4b5c-96cf-96e103300a55" config-ref="HTTP_Listener_config" path="/continue"/>
          <try doc:name="Try" doc:id="b934ba3a-2a17-4621-a898-ec6d3496da39" >
              <ee:transform doc:name="Transform Message" doc:id="fc27848c-2ba3-4382-b6ab-01edff9183cb" >
                   <ee:message >
                        <ee:set-payload ><![CDATA[%dw 2.0
output application/json
     id: as String
              <error-handler >
                   <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="8930dbae-a100-4eae-bd26-9f9074a9eea0" type="ANY">
                        <logger level="INFO" doc:name="Logger" doc:id="be5b001b-9852-4756-aeed-ee0d66080ca4" message="in processor level on error continue"/>
          <logger level="INFO" doc:name="Logger" doc:id="1d75ec01-86b4-47de-b996-53d61f834c80" message="last logger"/>
          <error-handler >
              <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="4d97d116-0700-48de-b233-d6247255632d" type="ANY">
                   <logger level="INFO" doc:name="Logger" doc:id="79f4203a-339c-4a43-8f9c-190b2145bd08" message="in flow level on error continue"/>
     <flow name="test_error_handlingFlow1" doc:id="77f2c5fa-7009-4bb1-8279-c7ba81a41951" >
          <http:listener doc:name="Listener" doc:id="d0493321-6491-4a38-8429-3cf0878e6240" config-ref="HTTP_Listener_config" path="/propagate"/>
          <try doc:name="Try" doc:id="aa6b898b-37e9-4239-b3c5-ce8c4b22abcc" >
              <ee:transform doc:name="Transform Message" doc:id="bb9017df-254b-4480-8ec5-08912cdff3c8" >
                   <ee:message >
                        <ee:set-payload ><![CDATA[%dw 2.0
output application/json
{ as String
              <error-handler >
                   <on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="37f12222-c1ec-4768-81f5-522ad08582ac" type="ANY">
                        <logger level="INFO" doc:name="Logger" doc:id="b1eb3fef-cbc3-48bb-88bb-cf6621a1aa3b" message="in processor level on error propagate"/>
          <logger level="INFO" doc:name="Logger" doc:id="27252a68-3cb7-497d-9f1c-3bd8af83d537" message="last logger"/>
          <error-handler >
              <on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="7c62b539-a945-4146-9b7b-371c016c078f" type="ANY">
                   <logger level="INFO" doc:name="Logger" doc:id="61efff1b-48e1-46b5-ac1a-5cc03acaea87" message="in flow level on error propagate"/>
     <error-handler name="test_error_handlingError_Handler" doc:id="a0a6cae1-1495-4693-9367-9bb1da3756cc" >
          <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="0f050e12-6a6e-46f6-ae8f-244c408fde08" type="ANY">
              <set-payload value="#[error.description]" doc:name="Set Payload" doc:id="0f414867-0aa8-4a32-b66e-27020db98734" />
     <flow name="test_error_handlingFlow3" doc:id="a0a35bca-f1b0-4c11-98d0-ed1dd01b551e" >
          <http:listener doc:name="Listener" doc:id="26f8be5c-5865-4246-90d0-e34f6215da5a" config-ref="HTTP_Listener_config" path="/raise"/>
          <try doc:name="Try" doc:id="3c105615-bc89-48e3-8bc4-50b66dc5906a" >
              <ee:transform doc:name="Transform Message" doc:id="68495cb9-5151-4b20-9542-8969fb9cdc8c" >
                   <ee:message >
                        <ee:set-payload ><![CDATA[%dw 2.0
output application/json
{ as String
          <raise-error doc:name="Raise error" doc:id="6ec851ea-4b47-4264-96c4-37ff0d41d95f" type="EXPRESSIONS: INCORRECT" description="Dataweave expression is incorrect" />
          <logger level="INFO" doc:name="Logger" doc:id="64e1e27b-89e3-4088-81cd-fef2912c2549" message="last logger"/>

No comments:

Post a Comment

If you have any doubt, please let me know

© 2020

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave

Converter Tools :

JSON to XML Converter XML to JSON Converter Decimal to Binary Decimal to Octal Binary to Decimal
Binary to Hexadecimal Binary to Octal Hexadecimal to Decimal Hexadecimal to Binary Hexadecimal to Octal
Octal to Decimal Octal to Binary Octal to Hexadecimal Number to Words Converter Text to Hex Converter
Hex to Text String to Binary Converter Binary to String Converter Word to HTML Converter Word to PDF Converter
JSON to YAML Converter CSV to JSON Converter XML to XSLT Converter XML to YAML Converter
JSON to CSV Converter JSON to TSV Converter CSV to TSV Converter CSV to XLS Converter

Image Tools :

PNG to JPG Converter PNG to BMP Converter PNG to GIF Converter JPG to PNG Converter JPG to BMP Converter
JPG to GIF Converter GIF to PNG Converter GIF to JPG Converter GIF to BMP Converter PNG to PDF Converter
JPEG to PDF Converter JPG to PDF Converter BMP to PDF Converter GIF to PDF Converter

String Utilities :

Reverse String Random String Generator Base64 Encoder Base64 Decoder Words Counter
Remove Accents Remove Duplicate Lines Remove Empty Lines Remove Line Breaks Remove Similar Lines
Sort Text Lines Reverse Text Lines Random Words Generator

Number Utilities :

Square Root Calculator Random Number Generator Area of Circle Calculator Date Calculator

Other Tools :

Find IP of Website Password Generator URL Encoder URL Decoder lorem ipsum Generator
IP to Hostname Port Checker JSON Escape JSON Unescape

Free Rest APIs for Testing :

GET Sample Rest APIs POST Sample Rest API PUT Sample Rest API PATCH Sample Rest API DELETE Sample Rest API
Login Sample Rest API User Registration Sample API User Registration Unsuccessful Sample Rest API Delay Response