Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Raise Error Component

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

Note that you can only use core types, such as SECURITY or custom ones. You cannot raise an error from another module like FILE:FILE_NOT_FOUND.

Core errors must use the implicit namespace, while custom ones are forced to declare one. The custom error namespace must not be used elsewhere in your app, meaning that you cannot use HTTP as a namespace if you are using HTTP operations, for example. Once you declare a custom namespace by using it in a raise-error, you can use it in other raise-error components and custom types.

The following example flow produces an ACCOUNT:INSUFFICIENT_FUNDS error when a transfer amount surpasses the available balance, preventing the transfer from taking place. Additionally, it generates a dynamic description by providing an expression with failure details.

Example: XML Configuration of the Flow

         
      
1
2
3
4
5
6
7
8
9
<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>

Raise Error Configuration

Field Value Description Example

Description

String or DataWeave expression

Specifies the error description.

description="Invalid email. Cannot complete transaction."

Type

String

Specifies the type of the error.

type="ORDER:INVALID_DATA"

This example raises an error with a static description and features a custom type using the ORDERS namespace:


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