diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java index 6ad400dad..599af231d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/LoginWidget.java @@ -90,6 +90,8 @@ public class LoginWidget extends Widget { } } catch (Exception e) { log.error(e); + // This widget should display an error message rather than throwing the exception + // up to the doMarkup() method, which would result in no display. values = showError(e); } values.put("urls", urls); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/Widget.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/Widget.java index 4e58cf722..3357bd092 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/Widget.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/widgets/Widget.java @@ -55,9 +55,17 @@ public abstract class Widget { HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request"); ServletContext context = (ServletContext) env.getCustomAttribute("context"); - WidgetTemplateValues values = process(env, params, request, context); + WidgetTemplateValues values = null; + + try { + values = process(env, params, request, context); + } catch (Exception e) { + log.error(e, e); + } + // The widget process() method may determine that nothing should display for the widget: - // for example, the login widget doesn't display if the user is already logged in. + // for example, the login widget doesn't display if the user is already logged in. This also + // applies if process() threw an error. if (values == null) { return ""; } @@ -92,7 +100,7 @@ public abstract class Widget { // } protected abstract WidgetTemplateValues process(Environment env, Map params, - HttpServletRequest request, ServletContext context); + HttpServletRequest request, ServletContext context) throws Exception; private String processMacroToString(Environment env, String widgetName, Macro macro, Map map) { StringWriter out = new StringWriter(); @@ -108,8 +116,8 @@ public abstract class Widget { // if it's already there or else add it. Leave this for later. Template template = new Template("widget", new StringReader(templateString), env.getConfiguration()); template.process(map, out); - } catch (Throwable th) { - log.error("Could not process widget " + widgetName, th); + } catch (Exception e) { + log.error("Could not process widget " + widgetName, e); } String output = out.toString(); log.debug("Macro output: " + output); @@ -163,8 +171,13 @@ public abstract class Widget { public String getMacroName() { return this.macroName; + } + } + + protected class WidgetProcessingException extends Exception { + WidgetProcessingException(String message) { + super(message); } - } }