Errors
Error Codes
When things go wrong with an API request, an error message is generated. These error messages contain an error code and a short description of what went wrong with the request. Below is a list of error codes you might encounter when using CrafterCMS and example responses for the corresponding error code:
Error Code |
Description |
Response Body Example |
---|---|---|
400 |
Bad Request |
|
401 |
Unauthorized |
|
403 |
Forbidden |
|
404 |
Not Found |
|
409 |
Conflict |
|
500 |
Internal Server Error |
|
For more details on error codes for specific APIs, please see the ReST API section in the following project specific documentation:
Error Pages
When Crafter Engine detects an error trying to fulfill a request it will also look for a custom error page to display in the browser, the process to add custom error pages is the following:
Create a new folder under
/templates/web/errors
Create a Freemarker template using as name the error code for which the page will be displayed, e.g.,
404.ftl
In the custom error templates developers are free to include any HTML/CSS/JS to make sure that the page matches the rest of the site.
Note
Custom Error pages are standalone templates, they are not associated with any site item and will not have
the model
object available.
Note
A valid context is required for custom error pages to render. If Crafter Engine is not able to load your site context due to a configuration or some other error condition, you will receive a default system error page.
Once the file is saved it will be used automatically in preview, for a delivery node you need to publish the new file so that it takes effect in the live site.
Example
Adding a Custom Error Page for the 404 Not Found
code: