This is my Blog.

It's full of opinions on a wide range of stuff.

Gracefully handling 404s with Lift

In my continuing effort to improve the wider knowledge of Lift, here's another great nugget that shows you how to provide a 404 handler powered from a Lift template

class Boot {
  def boot {
    // ...other stuff...

      case (req,failure) => 


And I have a 404.html file in the ./webapp/404.html with the contents:

<lift:surround with="default" at="content">
  <p>Wow, we totally couldn't find your page. Sorry about that.</p>

Then whenever a user browses to a URL that is not supported by your application, you can give them a friendly (and nicely designed) webpage rather than some technical message about 404s.

Note: The only cavet is not to use the <lift:menu /> snippet within your 404 template because Lift is unable to calculate the SiteMap when its a URL that is not accounted for within that scheme.

UPDATE The above note is now redundant because of commit by Marius on issue 376

blog comments powered by Disqus