Contact Us 1-800-596-4880

APIkit for REST Error Handling Reference

When something goes wrong with a part of your flow, you get a message with an error type.

APIkit for REST Error Types

APIkit for REST defines the following error types:

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

APIkit scaffolder generates error-handling code based on the most widely used HTTP status code responses, which are mapped to the error types and messages described as follows:

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

The following code shows an error handler for an HTTP 400 response, which you can use to build your own 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