Description
Suppose I like the default error handling of Spring Boot for Spring Web MVC, but I just want to return a different HTTP status for specific exceptions: for instance, I would like to return 404 when a FileNotFoundException
is thrown, instead of the default 500.
The quickest way to do this would be to define a @Bean
implementing ErrorAttributes
, by extending DefaultErrorAttributes
changing just addStatus(Map<String, Object>, RequestAttributes)
to return 404 in case getError(WebRequest)
returns a FileNotFoundException
. However, this is not currently possible because addStatus(Map<String, Object>, RequestAttributes)
is private!
Other methods like addErrorDetails(Map<String, Object>, WebRequest, boolean)
, addErrorMessage(Map<String, Object>, Throwable)
and addStackTrace(Map<String, Object>, Throwable)
could simplify quick customisations if they were protected...