When sending an error response, expose the encountered exception as a "org.springframework.web.util.WebUtils.EXCEPTION" request attribute.
This request attribute is similar to the standard servlet "javax.servlet.error.exception" request attribute, but is more flexible since the response won't be automatically handled by the servlet container as an INTERNAL_SERVER_ERROR error page.
Issue: SPR-11686
Comment From: rstoyanchev
On a second thought, I've done something a little different, treating this as an evolution of the DispatcherServlet's existing exception resolution, which currently exposes the resolved exception in the model but does nothing when a HandlerExceptionResolver returns an empty ModelAndView (i.e. status code set).