views:

244

answers:

1

How to make error handlers in Lift? I have html page with some snippets, if one of those snippets throws an exception I want to catch it and redirect to some user friendly error page.

How to do this in catch-all manner? I do not want to put error handling to each snippet separately. I am looking something like this in Wicket.

+6  A: 

When in doubt, check LiftRules API.

According this post something like this should work:

LiftRules.exceptionHandler.prepend { 
  case ("production", Req(path, "", GetRequest), SomeException) => { 
    Log.error("MELT DOWN!!") 
    RedirectResponse("/") 
  } 
} 

The signature of the exception handler type is:

type ExceptionHandlerPF = PartialFunction[(Props.RunModes.Value, Req, 
  Throwable), LiftResponse] 
Juha Syrjälä