causedBy(@DesignOnlyType error: Error, errorType: String): Boolean

This function matches an error by its type, like an error handler does.

causedBy is useful when you need to match by a super type, but the specific sub-type logic is also needed. It can also useful when handling a COMPOSITE_ROUTING error that contains child errors of different types.


Name Description


Optional. An Error type.


A string that identifies the error, such as HTTP:UNAUTHORIZED.


This XML example calls causedBy from a when expression in a Mule error handling component to handle a SECURITY error differently depending on whether it was caused by an HTTP:UNAUTHORIZED or HTTP:FORBIDDEN error. Notice that the first expression passes in the error (an Error type) explicitly, while the second one passes it implicitly, without specifying the value of the parameter. Note that error is the variable that DataWeave uses for errors associated with a Mule message object (see DataWeave Variables for Mule Runtime).


<error-handler name="securityHandler">
  <on-error-continue type="SECURITY">
    <!-- general error handling for all SECURITY errors -->
      <when expression="#[Mule::causedBy(error, 'HTTP:UNAUTHORIZED')]">
        <!-- specific error handling only for HTTP:UNAUTHORIZED errors -->
      <when expression="#[Mule::causedBy('HTTP:FORBIDDEN')]">
        <!-- specific error handling only for HTTP:FORBIDDEN errors -->

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!