spring-projects/spring-framework — pull request #644 by karlbennett (2014-09-13 06:37:05+00:00)
Title: Added 406 Not Acceptable response support for @ExceptionHandler methods

I found this while writing a file server when testing not found errors. When I attempted to handle my
not found exception for the file `Text.txt` I got a 500 instead of a 404. This is because I don't have a
message converter for `text/plain` so when the my hander method returns, the error cannot be
marshelled and an `HttpMediaTypeNotAcceptableException` is thrown by the resolver. This I would
expect to produce a 406 not a 500. The 500 happens because the
`HttpMediaTypeNotAcceptableException` is just logged and null returned, this indicates to the framework
that my not found exception wasn't actually resolved so it is then thrown up out into the web server.

I have updated the `ExceptionHandlerExceptionResolver` to propagate exceptions thrown from
`@ExceptionHandler` methods up to the `HandlerExceptionResolverComposite`. The
`HandlerExceptionResolverComposite` now catches the propagated exception and passes
that through the exception resolvers to see if it too can be handled. This prevents
the current behaviour of `HttpMediaTypeNotAcceptableException`s produced by
`@ExceptionHandler` methods causing HTTP 500s. They now produce HTTP 406 responses as
expected. It also allows the use of the defaul Spring MVC exceptions from within exception
`@ExceptionHandler` methods.

Issue: SPR-12188