10.1 Mule 4 Error Object Hierarchy & Custom Error Types

Key Takeaways

  • The Mule 4 Error Object (error) is automatically instantiated upon exception occurrence and contains critical diagnostic properties including error.description, error.detailedDescription, error.errorType, error.errorMessage, and error.childErrors.
  • The Error Type hierarchy forms a taxonomy tree rooted at ANY, allowing hierarchical matching where catching broad types (e.g., HTTP:ANY or ANY) catches all specialized subtypes (e.g., HTTP:CONNECTIVITY or HTTP:NOT_FOUND).
  • The CRITICAL branch of the hierarchy (e.g., FATAL_JVM_ERROR, OUT_OF_MEMORY, OVERLOAD) encompasses fatal system-level errors that cannot be intercepted, handled, or suppressed by application error handlers.
  • The error.errorMessage property preserves the complete MuleMessage (payload and attributes) returned by failing downstream systems (such as HTTP 4xx/5xx responses), while error.childErrors holds route-level failures from composite routers like Scatter-Gather.
  • Custom error types are defined dynamically using the <raise-error> component with the type="CUSTOM_NAMESPACE:IDENTIFIER" syntax and inherit automatically from the root ANY error type.
Last updated: August 2026

Mule 4 Error Object Hierarchy & Custom Error Types

In Mule 4, error handling is fundamentally re-architected around an explicit, declarative, and type-safe error handling framework. Unlike earlier Mule versions or traditional Java-based frameworks that rely on low-level Java exception classes, Mule 4 abstracts failures into a structured Error Object and a declarative Error Type Hierarchy. Understanding the composition of the Error Object, how error namespaces operate, and how to define and raise custom business errors is a foundational requirement for the Salesforce Certified MuleSoft Developer I examination.


1. Mule 4 Error Object Architecture

Whenever a message processor, connector operation, or routing component throws an exception during message processing, the Mule runtime intercepts the failure, halts normal sequential flow execution, and instantiates an immutable Error Object bound to the keyword error.

+---------------------------------------------------------------------------------------------------+
|                                    MULE 4 ERROR OBJECT STRUCTURE                                  |
|                                                                                                   |
|   error                                                                                           |
|   |                                                                                               |
|   +--- description              : String  ("HTTP GET on 'https://api.acme.com/v1/users' failed") |
|   +--- detailedDescription      : String  ("HTTP GET on resource failed with status code 404")    |
|   +--- exception                : Object  (Underlying Java Exception / Stack Trace)               |
|   +--- childErrors              : Object  (Map of child Error Objects, e.g. in Scatter-Gather)    |
|   |                                                                                               |
|   +--- errorType                : Object  (Complex Error Type Definition)                         |
|   |    +--- namespace           : String  ("HTTP")                                                |
|   |    +--- identifier          : String  ("NOT_FOUND")                                           |
|   |    +--- parentErrorType     : Object  (Reference to parent type: HTTP:ANY -> ANY)             |
|   |                                                                                               |
|   +--- errorMessage             : MuleMessage (Response message emitted by the failing target)     |
|        +--- payload             : Object  ({ "code": "USER_NOT_FOUND", "message": "User #88..." })|
|        +--- attributes          : Object  ({ statusCode: 404, headers: { ... } })                 |
+---------------------------------------------------------------------------------------------------+

Key Properties of the error Object

PropertyData TypeDescription & Practical Usage
error.descriptionStringA concise, human-readable summary of the error (e.g., "HTTP GET on resource failed: Not Found (404)"). Ideal for standard log output.
error.detailedDescriptionStringA more exhaustive diagnostic description of the failure, often including URI paths, query parameters, or internal component states.
error.errorTypeObjectA structured object describing the exact classification of the error within the Mule taxonomy. Contains namespace, identifier, and parentErrorType.
error.errorType.namespaceStringThe domain or module that originated the error (e.g., "HTTP", "DB", "VALIDATION", "MULE", or a custom business namespace like "ORDER").
error.errorType.identifierStringThe specific failure classification within the namespace (e.g., "CONNECTIVITY", "NOT_FOUND", "BAD_SQL_SYNTAX", "INVALID_BOOLEAN").
error.errorType.parentErrorTypeObjectThe immediate parent ErrorType in the hierarchy. For example, HTTP:NOT_FOUND has parent HTTP:CLIENT_SECURITY or HTTP:ANY, which in turn has parent ANY.
error.errorMessageMuleMessageWhen a remote operation fails (such as an <http:request> returning an HTTP 4xx or 5xx response), error.errorMessage contains the actual MuleMessage returned by that remote server, preserving both error.errorMessage.payload (the backend error body) and error.errorMessage.attributes (e.g., response headers and status code).
error.childErrorsCollection / MapContains child error objects when composite operations fail. Most notably populated when a <scatter-gather> router fails with MULE:COMPOSITE_ROUTING or when a <parallel-foreach> encounters route-level failures.
error.exceptionObjectThe raw underlying Java exception instance and stack trace (primarily used for advanced debugging).

[!IMPORTANT] Preserving Backend API Error Payloads via error.errorMessage A very common certification exam scenario asks how to retrieve the exact JSON or XML error response sent by an external REST API when an <http:request> call fails with status 400, 404, or 500. In Mule 4, the external response payload is stored in error.errorMessage.payload, NOT in error.description or the top-level payload. Accessing payload inside an error handler will reflect whatever payload was in the flow prior to the failing processor, unless explicitly overwritten.


2. Mule 4 Error Type Hierarchy

Mule 4 structures all error types into a single, unified taxonomy tree. At the highest level, errors are divided into two fundamental branches: ANY and CRITICAL.

                                   [ ERROR ROOT ]
                                         |
                    +--------------------+--------------------+
                    |                                         |
                 [ ANY ]                                 [ CRITICAL ]
             (Catchable Errors)                     (Non-Catchable Errors)
                    |                                         |
     +--------------+--------------+                          +-- FATAL_JVM_ERROR
     |              |              |                          +-- OUT_OF_MEMORY
[ CORE TYPES ] [ CONNECTORS ] [ CUSTOM TYPES ]                +-- OVERLOAD
     |              |              |
     +-- EXPRESSION +-- HTTP       +-- ORDER:INVALID_ITEM
     |              |   +-- CONNECTIVITY
     +-- ROUTING    |   +-- NOT_FOUND
     |   +-- COMPOSITE_ROUTING
     |              +-- DB
     +-- SECURITY       +-- CONNECTIVITY
     |   +-- CLIENT_SECURITY
     |                  +-- VALIDATION
     +-- TRANSFORMATION     +-- INVALID_BOOLEAN

The ANY Hierarchy (Catchable Errors)

ANY is the root type of all catchable errors. Any error handler configured with type="ANY" will intercept any error falling under this branch, regardless of the connector, module, or custom namespace.

The CRITICAL Hierarchy (Non-Catchable Errors)

CRITICAL errors represent fatal, unrecoverable system or JVM-level failures where runtime stability is compromised. CRITICAL errors cannot be handled or caught by <on-error-continue> or <on-error-propagate> scopes. When a CRITICAL error occurs, Mule logs the failure and immediately halts execution.

Standard CRITICAL error types include:

  • FATAL_JVM_ERROR: An unrecoverable JVM crash or internal error.
  • OUT_OF_MEMORY: The JVM has exhausted its heap space.
  • OVERLOAD: The system is overloaded and unable to allocate threads or memory buffers.

3. Core Built-In Error Namespaces and Identifiers

Mule 4 standardizes error types using the format NAMESPACE:IDENTIFIER. All namespaces and identifiers are uppercase.

Built-in Core and Connector Error Taxonomy

NamespaceError TypeHierarchy / ParentCause & Trigger Condition
MULEMULE:ANYANYRoot error type for all core Mule runtime errors.
MULEMULE:EXPRESSIONMULE:ANYA DataWeave expression failed evaluation (e.g., null pointer, invalid coercion, divide by zero).
MULEMULE:ROUTINGMULE:ANYAn issue occurred while routing a message.
MULEMULE:COMPOSITE_ROUTINGMULE:ROUTINGOne or more routes in a <scatter-gather> failed. Child errors accessible via error.childErrors.
MULEMULE:STREAM_MAXIMUM_SIZE_EXCEEDEDMULE:ANYA non-repeatable stream exceeded the in-memory or disk buffer size limit.
MULEMULE:REDELIVERY_EXHAUSTEDMULE:ANYA message has exceeded its configured max redelivery attempts.
HTTPHTTP:CONNECTIVITYCONNECTIVITYConnection to remote HTTP endpoint failed (DNS failure, connection refused, TCP timeout).
HTTPHTTP:NOT_FOUNDHTTP:CLIENT_SECURITY / ANYThe HTTP Request received a 404 Not Found response code.
HTTPHTTP:UNAUTHORIZEDHTTP:CLIENT_SECURITYThe HTTP Request received a 401 Unauthorized response code.
HTTPHTTP:FORBIDDENHTTP:CLIENT_SECURITYThe HTTP Request received a 403 Forbidden response code.
HTTPHTTP:BAD_REQUESTHTTP:ANYThe HTTP Request received a 400 Bad Request response code.
HTTPHTTP:METHOD_NOT_ALLOWEDHTTP:ANYThe HTTP Request received a 405 Method Not Allowed response code.
HTTPHTTP:TIMEOUTTIMEOUTHTTP request timed out waiting for server response (responseTimeout exceeded).
HTTPHTTP:PARSINGMULE:TRANSFORMATIONFailed to parse HTTP request or response headers/body.
DBDB:CONNECTIVITYCONNECTIVITYDatabase connection pool exhausted or database server unreachable.
DBDB:BAD_SQL_SYNTAXDB:ANYSQL statement contains a syntax error, invalid table, or missing column.
DBDB:QUERY_EXECUTIONDB:ANYDatabase query execution failed (e.g., primary key violation, constraint check failure).
VALIDATIONVALIDATION:INVALID_BOOLEANVALIDATION:ANY<validation:is-true> or <validation:is-false> evaluated to invalid state.
VALIDATIONVALIDATION:NULLVALIDATION:ANY<validation:is-not-null> found a null value.
VALIDATIONVALIDATION:EMPTY_COLLECTIONVALIDATION:ANY<validation:is-not-empty-collection> received an empty array.
APIKITAPIKIT:BAD_REQUESTMULE:VALIDATIONIncoming request fails RAML/OAS schema validation (returns HTTP 400).
APIKITAPIKIT:NOT_FOUNDMULE:ROUTINGNo matching API resource path defined in the API specification (returns HTTP 404).
APIKITAPIKIT:METHOD_NOT_ALLOWEDMULE:ROUTINGHTTP method not permitted on the requested resource (returns HTTP 405).
APIKITAPIKIT:NOT_ACCEPTABLEMULE:ROUTINGAccept header cannot be satisfied by API (returns HTTP 406).
APIKITAPIKIT:UNSUPPORTED_MEDIA_TYPEMULE:ROUTINGContent-Type header not supported by API resource (returns HTTP 415).

Generalization and Matching Rules

Because error types exist in a hierarchical taxonomy:

  • An error handler matching ANY will match all errors above except CRITICAL.
  • An error handler matching CONNECTIVITY will catch both HTTP:CONNECTIVITY and DB:CONNECTIVITY.
  • An error handler matching HTTP:ANY will catch HTTP:NOT_FOUND, HTTP:UNAUTHORIZED, HTTP:CONNECTIVITY, and all other HTTP:* errors.
  • An error handler matching HTTP:CLIENT_SECURITY will catch HTTP:UNAUTHORIZED and HTTP:FORBIDDEN.

4. Custom Error Types & The <raise-error> Processor

In real-world enterprise applications, business rule failures (e.g., insufficient account balance, customer not found, invalid inventory quantity) should be handled using the same declarative error mechanism as technical exceptions. Mule 4 enables developers to throw custom errors using the <raise-error> processor.

Declaring Custom Errors

<flow name="process-withdrawal-flow" doc:name="Process Withdrawal Flow">
    <http:listener config-ref="HTTP_Listener_config" path="/accounts/{id}/withdraw" doc:name="Listener"/>
    
    <!-- Validate Account Balance -->
    <choice doc:name="Check Balance">
        <when expression="#[vars.accountBalance &lt; payload.amount]">
            <!-- Raise Custom Business Error -->
            <raise-error 
                type="ACCOUNT:INSUFFICIENT_FUNDS" 
                description="The account balance is insufficient for the requested withdrawal amount." 
                doc:name="Raise Insufficient Funds"/>
        </when>
        <otherwise>
            <logger level="INFO" message="Funds verified. Processing transaction..." doc:name="Log OK"/>
        </otherwise>
    </choice>
    
    <!-- Error Handler in Flow -->
    <error-handler>
        <!-- Catch specific custom error -->
        <on-error-continue type="ACCOUNT:INSUFFICIENT_FUNDS" doc:name="Catch Insufficient Funds">
            <set-payload value="#[{ 'error': 'DECLINED', 'message': error.description, 'type': error.errorType.identifier }]" doc:name="Set Payload"/>
            <set-variable variableName="httpStatus" value="422" doc:name="Set 422 Status"/>
        </on-error-continue>
        
        <!-- Catch all other custom ACCOUNT errors -->
        <on-error-propagate type="ACCOUNT:ANY" doc:name="Catch Other Account Errors">
            <logger level="ERROR" message="#['General Account error: ' ++ error.description]" doc:name="Log Error"/>
        </on-error-propagate>
    </error-handler>
</flow>

Rules for Custom Error Types:

  1. Format: Must follow the CUSTOM_NAMESPACE:IDENTIFIER pattern (e.g., ORDER:ITEM_OUT_OF_STOCK, AUTH:EXPIRED_TOKEN).
  2. Case Sensitivity: Both namespace and identifier must consist of uppercase letters, numbers, and underscores.
  3. Reserved Namespaces: You must not use reserved system namespaces (MULE, HTTP, DB, FILE, WSC, VALIDATION, APIKIT, etc.) for custom errors.
  4. Hierarchy Inheritance: Custom error types automatically become children of the root ANY type. They also automatically support the NAMESPACE:ANY wildcard (e.g., matching ACCOUNT:ANY catches ACCOUNT:INSUFFICIENT_FUNDS, ACCOUNT:NOT_FOUND, etc.).

5. Inspecting Error Details in DataWeave

Inside error handler message processors (such as <ee:transform>, <set-payload>, or <logger>), developers can inspect the error object using DataWeave to construct standardized API error responses conforming to RFC 7807:

%dw 2.0
output application/json
---
{
    timestamp: now(),
    status: vars.httpStatus default 500,
    errorType: {
        namespace: error.errorType.namespace default "UNKNOWN",
        identifier: error.errorType.identifier default "UNKNOWN",
        canonicalName: (error.errorType.namespace default "UNKNOWN") ++ ":" ++ (error.errorType.identifier default "UNKNOWN")
    },
    message: error.description,
    detailedMessage: error.detailedDescription,
    backendResponse: error.errorMessage.payload default null,
    failedRouteErrors: error.childErrors default null
}

6. Exam Watch: Core Error Hierarchy Scenarios

[!IMPORTANT] Accessing error.errorMessage.payload vs payload When an HTTP Request operation fails with a 4xx/5xx status code, the response body from the remote server is placed in error.errorMessage.payload. The top-level payload variable in the flow remains the payload that existed before the failing component executed.

[!WARNING] CRITICAL Errors Cannot Be Caught If an exam question asks what error handler scope intercepts a MULE:FATAL_JVM_ERROR or MULE:OUT_OF_MEMORY, the answer is none. CRITICAL errors bypass all <error-handler>, <on-error-continue>, and <on-error-propagate> scopes.

[!TIP] Matching Order Hierarchy When an error occurs, Mule matches against the most specific type first. If an error handler has a scope matching HTTP:CONNECTIVITY and a scope matching CONNECTIVITY, an HTTP:CONNECTIVITY error will match HTTP:CONNECTIVITY. However, if the scopes are defined sequentially in the XML, Mule evaluates them in declaration order!

Test Your Knowledge

A Mule flow sends a GET request to an external customer REST service using an HTTP Request operation. The remote service returns an HTTP 404 Not Found status with the response body: { "code": "ERR_CUST_404", "message": "Customer ID 5542 does not exist." }. Inside the flow's error handler, which DataWeave expression accesses the JSON response body returned by the remote service?

A
B
C
D
Test Your Knowledge

A Mule application experiences severe system stress during peak load. Which of the following error types belongs to the CRITICAL hierarchy branch and therefore CANNOT be caught, intercepted, or suppressed by an On-Error Continue or On-Error Propagate scope?

A
B
C
D
Test Your Knowledge

A developer needs to validate incoming order items in a Mule flow. If an item is out of stock, the flow must halt processing and raise a custom business error with namespace INVENTORY and identifier OUT_OF_STOCK, along with an explanation message. Which XML component configuration correctly raises this error?

A
B
C
D
Test Your Knowledge

A flow contains an error handler with three declared scopes in the following order: Scope 1 handles HTTP:CONNECTIVITY, Scope 2 handles HTTP:ANY, and Scope 3 handles ANY. During flow execution, an HTTP Request component fails with an HTTP:UNAUTHORIZED error (status 401). How does Mule match and execute these error handling scopes?

A
B
C
D