vendredi 27 février 2015

Force Spring to always report exceptions as JSON

How do I force Spring to always convert uncaught exception to JSON instead of HTML page?


This is what I get when request is made from Chrome's REST client plugin:



{
timestamp: 1425041457798
status: 404
error: "Not Found"
exception: "com.some.my.Exception"
message: "/rrr does not exist"
path: "/test/rrr"
}


But this is what I get when I access it from browser or from Jersey API (you see parsed HTML):


Whitelabel Error Page


This application has no explicit mapping for /error, so you are seeing this as a fallback.


Fri Feb 27 13:37:27 CET 2015There was an unexpected error (type=Not Found, status=404).No message available

I know this can be done somehow by setting the request headers but I want JSON response to be the only variant.


Aucun commentaire:

Enregistrer un commentaire