I've written a custom StatusService to catch application level exceptions, and overridden the getRepresentation() method to create a custom representation of the error to send to the client.
It is an AJAX app, so I want to send a JSON representation if the accept-header indicates JSON, and I want to send HTML if the accept-header indicates HTML. So I need content negotiation, but it is not your typical resource-oriented content negotiation, since this is an error condition. The signature of StatusService.getRepresentation is protected Representation getRepresentation(Status status, Request request, Response response) So I have access to the list of accept headers by calling request.getClientInfo().getAcceptedMediaTypes() The question is, how do I reliably parse this list to figure out whether JSON or HTML is preferred? I suspect I need to do something with Variants, since Variant has a method isCompatible(). But I think I need something more than isCompatible(), since I want to know which of the two is PREFERRED, based on the q values, etc, not just whether it is compatible or not. I poked around in the Restlet source code for a while to see where the automagical content-negotiation occurs for resources, to see if there was a code snippet I could steal, but I couldn't locate it. Thanks... -- View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Error-responses-in-JSON-or-HTML-tp5436617p5436617.html Sent from the Restlet Discuss mailing list archive at Nabble.com. ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2648232

