What server are you using?
I think it might not be jersey that handles these things but rather the server.
I found this for jetty (not sure what you’re using):
https://wiki.eclipse.org/Jetty/Howto/Custom_Error_Pages
Thanks,
Jasmine
From: Bobby Bissett [mailto:bbissett_at_gmail.com]
Sent: Wednesday, November 18, 2015 3:59 PM
To: users_at_jersey.java.net
Subject: [Jersey] Re: returning default jersey responses as json
On Wed, Nov 18, 2015 at 2:41 PM, Jennifer Sears <jsears_at_galtech.net<mailto:jsears_at_galtech.net>> wrote:
Have you tried using a custom ObjectMapper? It sounds like you need to map your exceptions like described at the link below.
Thanks for the quick response. My exceptions (meaning anything I throw or catch) are all ok since I can throw a custom Exception that can generate the JSON. It's the cases where my code isn't even called that I don't know how to handle.
For instance, when someone hits
http://myserver/this_is_not_a_real_url I don't know if Jersey generates an exception internally or if it just sees that the URI doesn't match anything and responds with the 404. If so, then maybe the mapping would work. I'll try that and just map to Exception to see if something useful pops out.
Cheers,
Bobby