NIHVIVO-3118 Add cause to error display on page and in email. Minor reformatting in error templates.

This commit is contained in:
ryounes 2011-08-12 19:12:34 +00:00
parent d2b3213c7b
commit fd585b15f3
4 changed files with 44 additions and 23 deletions

View file

@ -48,21 +48,20 @@ public class FreemarkerConfigurationLoader {
} }
protected String getThemeDir(ApplicationBean appBean) { protected String getThemeDir(ApplicationBean appBean) {
String themeDir = null;
if (appBean == null) { if (appBean == null) {
log.error("Cannot get themeDir from null application bean"); log.error("Cannot get themeDir from null application bean");
return null; return null;
} else {
themeDir = appBean.getThemeDir();
if (themeDir == null) {
log.error("themeDir is null");
return null;
}
} }
String themeDir = appBean.getThemeDir();
if (themeDir == null) {
log.error("themeDir is null");
return null;
}
return themeDir.replaceAll("/$", ""); return themeDir.replaceAll("/$", "");
} }
protected FreemarkerConfiguration getConfigForTheme(String themeDir, VitroRequest vreq) { protected FreemarkerConfiguration getConfigForTheme(String themeDir, VitroRequest vreq) {
/* The Configuration is theme-specific because: /* The Configuration is theme-specific because:

View file

@ -146,6 +146,18 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String stackTrace = sw.toString(); String stackTrace = sw.toString();
adminErrorData.put("stackTrace", stackTrace); adminErrorData.put("stackTrace", stackTrace);
sw = new StringWriter();
Throwable c = t.getCause();
String cause;
if (c != null) {
c.printStackTrace(new PrintWriter(sw));
cause = sw.toString();
} else {
cause = "";
}
adminErrorData.put("cause", cause);
adminErrorData.put("datetime", new Date()); adminErrorData.put("datetime", new Date());
templateMap.put("errorOnHomePage", this instanceof HomePageController); templateMap.put("errorOnHomePage", this instanceof HomePageController);
@ -174,6 +186,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
doResponse(vreq, response, rv); doResponse(vreq, response, rv);
} catch (TemplateProcessingException e) { } catch (TemplateProcessingException e) {
// We'll get here if the error was in one of the page templates; then attempting
// to display the error page also generates an error.
throw new ServletException(); throw new ServletException();
} }
} }

View file

@ -14,12 +14,16 @@
<p><strong>Error message:</strong> ${adminErrorData.errorMessage}</p> <p><strong>Error message:</strong> ${adminErrorData.errorMessage}</p>
</#if> </#if>
<#if adminErrorData.stackTrace?has_content> <#if adminErrorData.stackTrace?has_content>
<div> <p>
<p><strong>Stack trace</strong> (full trace available in the vivo log):</p> <strong>Stack trace</strong> (full trace available in the vivo log): ${adminErrorData.stackTrace}
${adminErrorData.stackTrace} </p>
</div>
<#if adminErrorData.cause?has_content>
<p><strong>Caused by:</strong> ${adminErrorData.cause}</p>
</#if>
</#if> </#if>
<#elseif ! errorOnHomePage> <#-- view for other users --> <#elseif ! errorOnHomePage> <#-- view for other users -->
<p>Return to the <a href="${urls.home}">home page</a>.</p> <p>Return to the <a href="${urls.home}">home page</a></p>
</#if> </#if>

View file

@ -17,18 +17,20 @@
</p> </p>
<p> <p>
<strong>Requested url:</strong> ${requestedUrl}. <strong>Requested url:</strong> ${requestedUrl}
</p> </p>
<p> <p>
<strong>Error message:</strong> ${errorMessage}. <strong>Error message:</strong> ${errorMessage}
</p> </p>
<p> <p>
<strong>Stack trace</strong> (full trace available in the vivo log): <strong>Stack trace</strong> (full trace available in the vivo log): ${stackTrace}
</p> </p>
<div>${stackTrace}</div> <#if cause?has_content>
<p><strong>Caused by:</strong> ${cause}</p>
</#if>
</body> </body>
</html> </html>
@ -37,13 +39,15 @@
<#assign text> <#assign text>
An error occurred on your VIVO site at ${datetime}. An error occurred on your VIVO site at ${datetime}.
Requested url: ${requestedUrl}. Requested url: ${requestedUrl}
Error message: ${errorMessage}. Error message: ${errorMessage}
Stack trace (full trace available in the vivo log): Stack trace (full trace available in the vivo log): ${stackTrace}
${stackTrace} <#if cause?has_content>
Caused by: ${cause}
</#if>
</#assign> </#assign>
<@email subject=subject html=html text=text /> <@email subject=subject html=html text=text />