Skip to content

Commit

Permalink
Use request attribute if available for error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Syer committed Oct 27, 2014
1 parent e8b59b9 commit 7bac737
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public ModelAndView resolveException(HttpServletRequest request,

private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
request.setAttribute(ERROR_ATTRIBUTE, ex);

}

@Override
Expand Down Expand Up @@ -120,7 +121,7 @@ private void addErrorDetails(Map<String, Object> errorAttributes,
addStackTrace(errorAttributes, error);
}
}
else {
if (error==null || errorAttributes.get("message")==null) {
Object message = getAttribute(requestAttributes,
"javax.servlet.error.message");
errorAttributes.put("message", message == null ? "No message available"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ public void servletMessage() throws Exception {
assertThat(attributes.get("message"), equalTo((Object) "Test"));
}

@Test
public void nullMessage() throws Exception {
this.request.setAttribute("javax.servlet.error.exception", new RuntimeException());
this.request.setAttribute("javax.servlet.error.message", "Test");
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(
this.requestAttributes, false);
assertThat(attributes.get("exception"),
equalTo((Object) RuntimeException.class.getName()));
assertThat(attributes.get("message"), equalTo((Object) "Test"));
}

@Test
public void unwrapServletException() throws Exception {
RuntimeException ex = new RuntimeException("Test");
Expand Down

0 comments on commit 7bac737

Please sign in to comment.