Commit 7bac7370 authored by Dave Syer's avatar Dave Syer

Use request attribute if available for error message

Fixes gh-1762, gh-1731
parent e8b59b9e
...@@ -75,6 +75,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -75,6 +75,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
private void storeErrorAttributes(HttpServletRequest request, Exception ex) { private void storeErrorAttributes(HttpServletRequest request, Exception ex) {
request.setAttribute(ERROR_ATTRIBUTE, ex); request.setAttribute(ERROR_ATTRIBUTE, ex);
} }
@Override @Override
...@@ -120,7 +121,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -120,7 +121,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
addStackTrace(errorAttributes, error); addStackTrace(errorAttributes, error);
} }
} }
else { if (error==null || errorAttributes.get("message")==null) {
Object message = getAttribute(requestAttributes, Object message = getAttribute(requestAttributes,
"javax.servlet.error.message"); "javax.servlet.error.message");
errorAttributes.put("message", message == null ? "No message available" errorAttributes.put("message", message == null ? "No message available"
......
...@@ -118,6 +118,17 @@ public class DefaultErrorAttributesTests { ...@@ -118,6 +118,17 @@ public class DefaultErrorAttributesTests {
assertThat(attributes.get("message"), equalTo((Object) "Test")); 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 @Test
public void unwrapServletException() throws Exception { public void unwrapServletException() throws Exception {
RuntimeException ex = new RuntimeException("Test"); RuntimeException ex = new RuntimeException("Test");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment