New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring MVC: Guidance on reporting un-handled errors as data when implementing a REST API [SPR-9290] #13928

Closed
spring-issuemaster opened this Issue Mar 30, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Mar 30, 2012

Keith Donald opened SPR-9290 and commented

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:
http://blog.newsplore.com/2010/08/04/restful-error-handling-with-tomcat-springmvc


Affects: 3.1.1

Issue Links:

  • #13053 Create separate handler stereotype for RESTful web services
  • #13921 Improved support for REST API error reporting
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Aug 21, 2012

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 11, 2012

Pavel Orehov commented

I'm trying to use that new feature but things does not work as expected.
http://forum.springsource.org/showthread.php?131688-Improved-support-for-REST-API-error-reporting-in-Spring-3-2-0-M2
Would appreciate any help.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Nov 11, 2012

Michael Osipov commented

A very reasonable issue which am fighting with too.
The reason in @ResponseStatus is actually not very helpful when you are in a international environment. I'd would need to return customized messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment