Contact Us 1-800-596-4880

APIkit for REST Error Handling Reference

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:

Error Type Description

APIKIT:BAD_REQUEST

Bad request

APIKIT:NOT_FOUND

Resource not found

APIKIT:METHOD_NOT_ALLOWED

Method not allowed

APIKIT:NOT_ACCEPTABLE

Not acceptable

APIKIT:UNSUPPORTED_MEDIA_TYPE

Unsupported media type

APIKIT:NOT_IMPLEMENTED

Not implemented

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:

Status Code Error Type Response Message

400

APIKIT:BAD_REQUEST

Bad request

404

APIKIT:NOT_FOUND

Resource not found

405

APIKIT:METHOD_NOT_ALLOWED

Method not allowed

406

APIKIT:NOT_ACCEPTABLE

Not acceptable

415

APIKIT:UNSUPPORTED_MEDIA_TYPE

Unsupported media type

501

APIKIT:NOT_IMPLEMENTED

Not implemented

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.

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