---
schema_version: "1"
id: b2f65595d52a271a271c5ff4dfb9d7239b6d74c6d283b2ee229d2f9cdcca2529
title: APIkit for REST Error Handling Reference
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/apikit/latest/apikit-error-handling-reference.md
canonical_url: https://docs.mulesoft.com/apikit/latest/apikit-error-handling-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 29c61c9b0728e6da1e7d8251175a83b57f1604fe2fc2098c66ced579fa7ad540
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: APIkit
version: 4.x
is-latest-version: true
---

# APIkit for REST Error Handling Reference

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

APIkit for REST maps common HTTP and routing failures to typed `APIKIT` errors you handle in Mule.
Use the error type list and status-code mapping in this reference to interpret failures and
customize responses. The scaffolder can generate baseline error handling that mirrors typical HTTP
status semantics.

## APIkit for REST Error Types

APIkit for REST defines error types that correspond to HTTP semantics:

<table><colgroup><col> <col></colgroup><thead><tr><th>Error Type</th><th>Description</th></tr></thead><tbody><tr><td><p>APIKIT:BAD_REQUEST</p></td><td><p>Bad request</p></td></tr><tr><td><p>APIKIT:NOT_FOUND</p></td><td><p>Resource not found</p></td></tr><tr><td><p>APIKIT:METHOD_NOT_ALLOWED</p></td><td><p>Method not allowed</p></td></tr><tr><td><p>APIKIT:NOT_ACCEPTABLE</p></td><td><p>Not acceptable</p></td></tr><tr><td><p>APIKIT:UNSUPPORTED_MEDIA_TYPE</p></td><td><p>Unsupported media type</p></td></tr><tr><td><p>APIKIT:NOT_IMPLEMENTED</p></td><td><p>Not implemented</p></td></tr></tbody></table>

## APIkit for REST Error Handling

The APIkit scaffolder generates error-handling code based on common HTTP status code responses. The
table maps each status to an error type and default message:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Status Code</th><th>Error Type</th><th>Response Message</th></tr></thead><tbody><tr><td><p>400</p></td><td><p>APIKIT:BAD_REQUEST</p></td><td><p>Bad request</p></td></tr><tr><td><p>404</p></td><td><p>APIKIT:NOT_FOUND</p></td><td><p>Resource not found</p></td></tr><tr><td><p>405</p></td><td><p>APIKIT:METHOD_NOT_ALLOWED</p></td><td><p>Method not allowed</p></td></tr><tr><td><p>406</p></td><td><p>APIKIT:NOT_ACCEPTABLE</p></td><td><p>Not acceptable</p></td></tr><tr><td><p>415</p></td><td><p>APIKIT:UNSUPPORTED_MEDIA_TYPE</p></td><td><p>Unsupported media type</p></td></tr><tr><td><p>501</p></td><td><p>APIKIT:NOT_IMPLEMENTED</p></td><td><p>Not implemented</p></td></tr></tbody></table>

## APIkit for REST Example Error

This sample shows an error handler for an HTTP 400 response, which you can adapt for custom status
codes and messages.

```xml
...
    <on-error-propagate type="APIKIT:BAD_REQUEST" doc:name="On Error Propagate">
        <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
            <ee:message>
                <ee:set-payload><![CDATA[%dw 2.0
    output application/json
    ---
    {message: "Bad request"}]]></ee:set-payload>
            </ee:message>
            <ee:variables>
                <ee:set-variable variableName="httpStatus">400</ee:set-variable>
            </ee:variables>
        </ee:transform>
    </on-error-propagate>
...
```

The main flow transmits an HTTP error response that encompasses an HTTP status code paired with an
associated message expressed in clear and straightforward language. In this example,
`message: "Bad request"`.

## See Also

- [Error Handlers](https://docs.mulesoft.com/mule-runtime/latest/error-handling)
