Play CMS has a set of predefined errors and error screens that can be used (or extended). 

Showing an error screen

Use the Error helper class (from a controller) like this:

// Returns the error screen with a 500 internal server error response code
return Error.internal("My error message");

Currently, these exist:

  • Error.notFound()
  • Error.internal()
  • Error.forbidden()
  • Error.unavailable()

This will

  • Return the ErrorPage object with key _internalError (the default error page blocks are created during setup)

  • The ErrorPage template (by default) shows the error number to all, and the error message only to admin users

  • Log the error message and create a unique error number as reference:

    [error] application - _internalError #1400678401348: Could not find homepage (page block with key 'homepage')

Customizing error screens

To create custom error screens / templates in your project:

  • Create a ErrorPage subclass which uses your template
  • Overwrite DefaultBootstrapper#getErrorPageInstance() to return an instance of your custom error page

Note: For more control, you can also overwrite the DefaultBootstrapper.createErrorPage*() methods.

Don't forget to call /reset to have your new error pages created.

Modify and translate content on error screens

These error screens are also cms pages, which means admins can add or modify their content, translate them etc. Edit them from the cms backend, they're placed under the System node in the navigation tree.