Give a web application the chance to globally translate domain specific

exceptions into friendly exceptions that preserve a sensible user experience.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1745 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2005-12-15 19:24:58 +00:00
parent b1e9073953
commit 777a00bc4e
2 changed files with 25 additions and 2 deletions
@@ -187,6 +187,17 @@ public class Application
{
}
/**
* If an exception propagates up from {@link Logic#invoke}, the application
* is given the chance to convert a low-level exception into a {@link
* FriendlyException} or a {@link RedirectException} which will be handled
* in the normal way.
*/
protected Exception translateException (Exception error)
{
return error;
}
/**
* This should be overridden by the application implementation to
* perform any necessary cleanup.
@@ -273,7 +273,6 @@ public class DispatcherServlet extends VelocityServlet
throws Exception
{
InvocationContext ictx = (InvocationContext)ctx;
String errmsg = null;
Logic logic = null;
// listen for exceptions so that we can report them
@@ -309,6 +308,7 @@ public class DispatcherServlet extends VelocityServlet
// otherwise massaged by the logic
rsp.setContentType("text/html; charset=" + _charset);
Exception error = null;
try {
// insert the application into the context in case the
// logic or a tool wishes to make use of it
@@ -352,7 +352,19 @@ public class DispatcherServlet extends VelocityServlet
logic.invoke(_app, ictx);
}
} catch (RedirectException re) {
} catch (Exception e) {
error = e;
}
// if an error occurred processing the template, allow the application
// to convert it to something more appropriate and then handle it
String errmsg = null;
try {
if (error != null) {
throw _app.translateException(error);
}
} catch (RedirectException re) {
ictx.getResponse().sendRedirect(re.getRedirectURL());
return null;