How to catch exceptions and redirect to error page in Lift?
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 lo开发者_开发问答oking something like this in Wicket.
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]
精彩评论