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:
  1. Set the status code: /request/status
  2. Set the value of /request/view to error.
  3. 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 your app/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
For any error code, the following set of error pages are searched for location, in the following order:
  1. error<status code>.<extension>
  2. error<class of status code>.<extension>
  3. error.<extension>.
The extension is determined by the extension search order, which is stored in the global context at /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.

Version 1.0.0.3.25591