---
schema_version: "1"
id: e6c2b06704060e679f77afc1b8f332b36c8ea95f56c38b8bd59e1e5d1e94dd2d
title: causedBy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-mule-functions-causedby.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-mule-functions-causedby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9c3f52d76f81ff3343913e62878fb53b51414263a2a3b8bf13481c19433d03f4
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# causedBy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## 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.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>error</code></p></td><td><p>Optional. An <code>Error</code> type.</p></td></tr><tr><td><p><code>errorType</code></p></td><td><p>A string that identifies the error, such as HTTP:UNAUTHORIZED.</p></td></tr></tbody></table>

### 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 Runtime](https://docs.mulesoft.com/dataweave/latest/dataweave-variables-context)).

#### Source

```XML
<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>
```
