Sometimes it seems like every tenth message to this list is asking a variation of this question. I know that we're free to define our own StatusService implementations, overriding getRepresentation, but wouldn't it be nice if the *default* StatusService had support that would let us throw a resource exception containing a Java object that was convertible to the error representation?
throw new ResourceException(Status.CLIENT_ERROR_GONE, myGoneErrorObject, initCause); // myGoneErrorObject converted by StatusService/ConvertService to error representation It would be particularly useful to be able to specific a Freemarker template and data model to supply HTML error representations. --tim On Thu, May 5, 2011 at 1:50 PM, Bruno Mendes <b.mende...@gmail.com> wrote: > How can I provide a custom error handler for a service? > > Case Study: I have this service which persists the Operation passed either > by xml or by json. The problem is, when a malformed structure is passed, the > server it returns a predefined error message. > @POST > @Consumes({"text/xml", "application/json"}) > public void save(Operation operation) { > operationDAO.save(operation); > } > > Where should I handle the exceptions to provide a different status code > other than 500 and custom messages. > The FAQ tells "If you want a different status when an exception is thrown, > you have to catch it manually at a lower level (inside the handle(Call) or > handleGet|Post|etc. method of your intermediary Restlet)", but following the > pattern from the jaxrs extension example I have a Resource > (OperationServerResource), an Application config (OperationApplication) and > the Server (for now it only has the OperationApplication being attached, but > later there is going to be a lot of applications). In this pattern, the only > place where I can override the handle() is at the server, but by doing this > I'll handle all specific exceptions from all bussiness classes (as > Operation) at the same place ;/. > Is there a different pattern I could use or a different way to handle the > exceptions than ovewriting the component's handle in the server? > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2731311 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2731327