Respect ModelAndView.status in @ExceptionHandler
Issue: SPR-14006
This commit is contained in:
@@ -1742,6 +1742,18 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
assertEquals("view", response.getForwardedUrl());
|
||||
}
|
||||
|
||||
@Test // SPR-14796
|
||||
public void modelAndViewWithStatusInExceptionHandler() throws Exception {
|
||||
initServletWithControllers(ModelAndViewController.class);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/exception");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
getServlet().service(request, response);
|
||||
|
||||
assertEquals(422, response.getStatus());
|
||||
assertEquals("view", response.getForwardedUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHead() throws ServletException, IOException {
|
||||
initServletWithControllers(ResponseEntityController.class);
|
||||
@@ -3302,6 +3314,20 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
public ModelAndView methodWithHttpStatus(MyEntity object) {
|
||||
return new ModelAndView("view", new ModelMap(), HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@RequestMapping("/exception")
|
||||
public void raiseException() throws Exception {
|
||||
throw new TestException();
|
||||
}
|
||||
|
||||
@ExceptionHandler(TestException.class)
|
||||
public ModelAndView handleException() {
|
||||
return new ModelAndView("view", new ModelMap(), HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class TestException extends Exception {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user