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,20 +48,19 @@ public class FreemarkerConfigurationLoader {
}
protected String getThemeDir(ApplicationBean appBean) {
String themeDir = null;
if (appBean == null) {
log.error("Cannot get themeDir from null application bean");
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("/$", "");
}
protected FreemarkerConfiguration getConfigForTheme(String themeDir, VitroRequest vreq) {

View file

@ -146,6 +146,18 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
String stackTrace = sw.toString();
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());
templateMap.put("errorOnHomePage", this instanceof HomePageController);
@ -174,6 +186,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
doResponse(vreq, response, rv);
} 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();
}
}

View file

@ -14,12 +14,16 @@
<p><strong>Error message:</strong> ${adminErrorData.errorMessage}</p>
</#if>
<#if adminErrorData.stackTrace?has_content>
<div>
<p><strong>Stack trace</strong> (full trace available in the vivo log):</p>
${adminErrorData.stackTrace}
</div>
</#if>
<p>
<strong>Stack trace</strong> (full trace available in the vivo log): ${adminErrorData.stackTrace}
</p>
<#if adminErrorData.cause?has_content>
<p><strong>Caused by:</strong> ${adminErrorData.cause}</p>
</#if>
</#if>
<#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>

View file

@ -17,18 +17,20 @@
</p>
<p>
<strong>Requested url:</strong> ${requestedUrl}.
<strong>Requested url:</strong> ${requestedUrl}
</p>
<p>
<strong>Error message:</strong> ${errorMessage}.
<strong>Error message:</strong> ${errorMessage}
</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>
<div>${stackTrace}</div>
<#if cause?has_content>
<p><strong>Caused by:</strong> ${cause}</p>
</#if>
</body>
</html>
@ -37,13 +39,15 @@
<#assign text>
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>
<@email subject=subject html=html text=text />