HTTP error handling
When problems occur on a Web site, error pages should be returned to the client.
You can use the rendering capabilities to provide custom error pages.
Rendering error pages
To display an error page, use the following required steps:- Set the status code:
/request/status - Set the value of
/request/viewtoerror. - Invoke zero.core.views.ViewEngine.render()
request.status = 404 ... // set any header values here request.view = "error" render()
Naming error pages
Error pages can be scripts, templates or HTML. You must place all error pages in yourapp/errors directory. An error page can represent a specific error code, the class of codes, or
a default page for all error codes.
<appRoot>
+ app/
+ errors/
- error404.groovy error page for status code = 404
- error5XX.gt error page for any error code >= 500 and < 600
- error.html default error page for all error codes
- error<status code>.<extension>
- error<class of status code>.<extension>
- error.<extension>.
/config/fileserver/defaultExtensions.
Error pages from dependencies
If the error page cannot be found in your application, the dependencies of your application are also searched using virtualized directories. zero.core provides a set of default error pages that the application can override. The default error page allows you to set a message,/request/error/message, and exception, /request/error/exception, to include in the resulting page.