Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Spring MVC: Guidance on reporting un-handled errors as data when implementing a REST API [SPR-9290] #13928
HttpServletResponse#sendError's default behavior for reporting unrecoverable errors such as 404, 405, 406, and 500 sends HTML back to the client, which is not appropriate for REST APIs where responses should be in the form of data (usually JSON, alternatively XML). Spring MVC currently doesn't provide any guidance on how to deal with this issue e.g. should the developer customize the sendError behavior by defining custom error page JSPs that return JSON? Do they instead configure something in Spring MVC itself? It'd be helpful to provide application developer guidance here.
This was a useful resource:
Rossen Stoyanchev commented
I've updated the reference docs with information on customizing the default Servlet container error page and added a sample project.
Also note that you need Tomcat 7.0.29 or higher to be able to define an <error-page> element in web.xml that contains only a location sub-element, i.e. is not mapped to any specific status code or exception type.
Pavel Orehov commented
I'm trying to use that new feature but things does not work as expected.