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
Deploy and test the project from soapui project
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 : <raise-error doc:name="Raise error" doc:id="810bf64f-d1cb-4371-a076-696b54ec1fc5" type="EMPLOYEE:INVALIDRECORD" description="Employee Name Is Null"></raise-error> (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) ********************************************************************************
Soap UI Project:RaiseErrorSoapUI application
Sample application: raiseerror sample application
Great Example!