I am coding some Spring REST services using Spring MVC. I have a requirement that any 500 (Internal Server Error) be sent back packaged as a json with Http Status = 500 and Http Body with the json string [“Internal Server Error”].
To do this i am extending OncePerRequestFilter and checking the status of Http Response. I am then constructing the body with the required json response.
Though this serves the purpose, it is messy. Is there a better design principle or spring/json class that I can configure with Spring which achieves the same purpose?
-Gotz
I believe that you can use the following structure:
1) Map HTTP 500 error to some view:
2) in your Controller create View which will return any Json Information you need.
Hope it helps.