APIkit Error Handling Reference

APIkit generates error-handling code based on the main error handling mechanism in Mule 4. If something goes wrong with a component, you get an error that is typed accordingly with a message. The generated code is available for the most widely-used HTTP status code responses, which are mapped to the types and error messages in the following table.

Status Code Type Message



Bad request



Resource not found



Method not allowed



Not acceptable



Unsupported media type

The following example of the HTTP 400 response shows the construction of the error handler. To add your own custom status code, following the pattern shown here.

 <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:set-payload><![CDATA[%dw 2.0
output application/json
{message: "Bad request"}]]></ee:set-payload>
                        <ee:set-variable variableName="httpStatus">400</ee:set-variable>

Every time a message throws an error, APIkit checks to see if the error matches the value of any on-error-propagate types defined in the project. The main flow in an APIkit project sends an HTTP error response consisting of an HTTP status code and corresponding plain-language message.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Give us your feedback!
We want to build the best documentation experience for you!
Help us improve with your feedback.
Take the survey!