Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 looking something like this in Wicket.

like image 207
Juha Syrjälä Avatar asked Feb 09 '10 19:02

Juha Syrjälä


1 Answers

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] 
like image 52
Juha Syrjälä Avatar answered Oct 13 '22 00:10

Juha Syrjälä