Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom 404 page handler with Play 2.0?

What’s the preferred way to handle 404 errors with Play 2.0 and show a nice templated view?

like image 768
Julien Richard-Foy Avatar asked Apr 03 '12 08:04

Julien Richard-Foy


People also ask

How do I test a custom error page?

To display a custom error page with an appropriate error code, use the <httpErrors> section only, and do not use the <customErrors> section. Add the following <httpErrors> section under <system.


1 Answers

You can override the onHandlerNotFound method on your Global object, e.g.:

object Global extends GlobalSettings {   override def onHandlerNotFound(request: RequestHeader): Result = {     NotFound(views.html.notFound(request))   } } 
like image 101
Julien Richard-Foy Avatar answered Oct 13 '22 12:10

Julien Richard-Foy