Learn how to put your digital team to work with MuleSoft for Agentforce.
Contact Us 1-800-596-4880

causedBy

DataWeave 2.2 is compatible and bundled with Mule 4.2. This version of Mule reached its End of LifeLeaving the Site on May 2, 2023, when Extended Support ended.

Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted.

MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements.

causedBy(Error, 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.

Parameters

Name Description

error

Optional. An Error type.

errorType

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

Example

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 RuntimeLeaving the Site).

Source

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