Raise Error Manually In Mule 4

 

In this tutorial we will demonstrate how to Raise Error  Manually In Mule 4

This core component generates a Mule error, as if a failure had occurred, which allows you to customize its description and type.

Use this component to only raise:

  • Core runtime errors, such as MULE:SECURITY, MULE:CONNECTIVITY, etc.
  • Custom error types

Raise Core Runtime Error Types

For core runtime error types, you must use the implicit namespace and identifier, you can only customize the error’s description message. For example:

<raise-error type=“MULE:CONNECTIVITY” description=“Error description message”/>

Raise Custom Error Types

For custom error types, declare a new namespace. The namespace of an error type should help you identify the origin of an error. For example:

<raise-error type=“ORDER:INVALID_DATA” description=“Email is invalid. Cannot complete transaction”/>

 

create a sample project to raise the error in case condition not fulfilled

Sample Input:

{
  "status":"success",
  "data":[{
    "id":"1",
    "employee_name":"",
    "employee_salary":320800,
    "employee_age":61,
    "profile_image":""
  }]
}

 

Create a project in anypoint studio and configure the listener to trigger the request

Configure the choice router condition and check if the employee name is null or not

 

Configure Raise Error Activity with Error Type and Description

 

Configure the On Error Propagate to send the Error Message to source system

Raise Error Component In Mule 4

 

Deploy and test the project from soapui project

Raise Error Component In Mule 4

 

Error Received on Console

ERROR 2020-04-10 21:25:52,752 [[MuleRuntime].cpuLight.09: [raiseerror].raiseerrorFlow.CPU_LITE @5a811b18] [event: b9eaf5b0-7b43-11ea-981e-040e3cd1eac7] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:

********************************************************************************
Message : Employee Name Is Null
Error type : EMPLOYEE:INVALIDRECORD
Element : raiseerrorFlow/processors/0/route/0/processors/0 @ raiseerror:raiseerror.xml:19 (Raise error)
Element XML : &lt;raise-error doc:name="Raise error" doc:id="810bf64f-d1cb-4371-a076-696b54ec1fc5" type="EMPLOYEE:INVALIDRECORD" description="Employee Name Is Null"&gt;&lt;/raise-error&gt;
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

 

Soap UI Project:RaiseErrorSoapUI application

Sample application: raiseerror sample application

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mayur Suresh Patil
Mayur Suresh Patil
3 months ago

Great Example!