users@jersey.java.net

Customize default error responses

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Fri, 29 Jan 2010 15:09:21 -0800

Hey folks,

I've been poking around but haven't found any threads or docs to explain
what i'm after. At least not recent ones.

So basically for our app all our error responses contain a JSON message to
explain the problem. That is fine for exceptions that come from my code
because i can just turn them into whatever HTTP error I want. My question
is can I customize the error body returned for HTTP errors that never reach
my code. For instance for a 415 method not allowed error I want to
construct a JSON response instead of the default html error. Is it possible
to do this? I looked at the ExceptionMapper but I'm not sure what exception
to map since the request is never really reaching my code. I could
implement some kind of catchall resource that will try to grab all requests
that aren't supported and creates the response but that feels kind of hacky.


Thanks
Chris