<raise-error
type="MULE:CONNECTIVITY"
description="Error description message" />
Raise Error (<raise-error/>)
Generates a Mule error to indicate that a failure occurred.
You can customize the error’s description and type. Use this component to raise:
-
Core runtime errors, such as
MULE:SECURITY
andMULE:CONNECTIVITY
. -
Custom error types.
You cannot raise an error from another connector or module, such as FILE:FILE_NOT_FOUND
or JSON:INVALID_SCHEMA
. You cannot use a connector’s existing namespace.
Component XML
This component supports the following XML structure:
Raise Error (<raise-error/>
) attributes are configurable through the UI and XML.
Attribute Name | Attribute XML | Description |
---|---|---|
Raise error (default) |
|
Editable name for the component to display in the canvas. |
N/A |
|
Automatically generated identifier for the component. |
Type |
|
The type of error. |
Description |
|
The error description. |
Examples
The following examples show how to raise a custom error when a user provides an invalid value while making an API request and raise a custom error after comparing a value received in an API response.
Example: Raising an Error After an Invalid User Input
The following example of a driving lessons platform checks that the user is over 16 years old. The flow raises a custom PRECONDITIONS:INCORRECT_AGE
error when the user enters an age less than 16 years.
<http:listener-config name="HTTP_Listener_config">
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="raise-error-example-flow">
<http:listener config-ref="HTTP_Listener_config" path="/test"/>
<choice> (1)
<when expression="#[message.attributes.queryParams.age < 16]"> (2)
<raise-error type="PRECONDITIONS:INCORRECT_AGE" description="Minimum age of 16 required to drive" />
</when>
<otherwise > (3)
<logger level="INFO" message="User age above 16 years. Allowed to drive"/>
</otherwise>
</choice>
<error-handler >
<on-error-continue enableNotifications="true" logException="true" type="PRECONDITIONS:INCORRECT_AGE"> (4)
<logger level="INFO" message="Minimum age to drive is 16 years old"/>
</on-error-continue>
<on-error-continue enableNotifications="true" logException="true" type="MULE:EXPRESSION"> (5)
<logger level="INFO" message="The parameter age is missing or invalid"/>
</on-error-continue>
</error-handler>
</flow>
1 | The Choice router components adds conditional processing to the flow. |
2 | If the age parameter sent in the request is less than 16 (http://localhost:8081/test?age=15 ), the Raise Error component raises the error type PRECONDITIONS:INCORRECT_AGE with the description Minimum age of 16 required to drive . |
3 | If the age parameter is greater than 16 in the request (http://localhost:8081/test?age=17 ), a Logger component returns the default message User age above 16 years. Allowed to drive . |
4 | An On-Error Continue component matches the type of the error PRECONDITIONS:INCORRECT_AGE and executes the Logger component inside its scope. The Logger component logs the error message Minimum age of 16 required to drive . |
5 | If no age parameter is passed in the request (http://localhost:8081/test ) the choice component automatically raises a MULE:EXPRESSION error when trying to evaluate the expression #[message.attributes.queryParams.age < 16] . No age parameter was provided in the request, so its value is null.
Then, an On-Error Continue component matches the type of the error |
Example: Raising an Error After Comparing Values
The following example makes a request to an API (https://unsecurebank.com/balance) and stores the returned account balance in the balance variable, then compares the variable with payload.amount
to determine if the operation is possible. The Choice router produces an ACCOUNT:INSUFFICIENT_FUNDS
error when a transfer amount surpasses the available balance, preventing the transfer from taking place. The description dynamically provides failure details.
<flow name="raise-error-example-flow">
<http:request url="https://unsecurebank.com/balance" target="balance"/>
<choice>
<when expression="#[payload.amount > vars.balance]">
<raise-error type="ACCOUNT:INSUFFICIENT_FUNDS" description="#['Cannot transfer $(payload.amount) since only $(vars.balance) are available.']"/>
</when>
</choice>
<http:request url="https://unsecurebank.com/transfer"/>
</flow>