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:
@@ -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
|
* This should be overridden by the application implementation to
|
||||||
* perform any necessary cleanup.
|
* perform any necessary cleanup.
|
||||||
|
|||||||
@@ -273,7 +273,6 @@ public class DispatcherServlet extends VelocityServlet
|
|||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
InvocationContext ictx = (InvocationContext)ctx;
|
InvocationContext ictx = (InvocationContext)ctx;
|
||||||
String errmsg = null;
|
|
||||||
Logic logic = null;
|
Logic logic = null;
|
||||||
|
|
||||||
// listen for exceptions so that we can report them
|
// listen for exceptions so that we can report them
|
||||||
@@ -309,6 +308,7 @@ public class DispatcherServlet extends VelocityServlet
|
|||||||
// otherwise massaged by the logic
|
// otherwise massaged by the logic
|
||||||
rsp.setContentType("text/html; charset=" + _charset);
|
rsp.setContentType("text/html; charset=" + _charset);
|
||||||
|
|
||||||
|
Exception error = null;
|
||||||
try {
|
try {
|
||||||
// insert the application into the context in case the
|
// insert the application into the context in case the
|
||||||
// logic or a tool wishes to make use of it
|
// logic or a tool wishes to make use of it
|
||||||
@@ -352,7 +352,19 @@ public class DispatcherServlet extends VelocityServlet
|
|||||||
logic.invoke(_app, ictx);
|
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());
|
ictx.getResponse().sendRedirect(re.getRedirectURL());
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user