Hi all, I'm finally writing some code after way too long of a hiatus,
and I'm of course getting hung up on some simple things.
With 2.0, what's the simplest way to return an error message?
I thought it was by throwing a ResourceException, like so:
@Post("form")
public void accept(Form form) throws ResourceException {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
"That's not right!");
}
But apparently the default StatusFilter doesn't use the "description"
field of the status. So my error response is very generic. The status
line is "HTTP/1.1 400 Bad Request" and the HTML representation only
includes the status name "Bad Request".
I know I can subclass StatusFilter and/or StatusService, but I'd be
surprised if the framework didn't provide a simple way to return an
error message without having to create custom classes.
I know I can create my own error representation right in my method,
but that also seems like a lot of boilerplate code just to send a
simple error message. I know it's only 2 lines of code:
getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
return new StringRepresentation("That's not right!");
But it still seems like a lot — especially if I want to return an HTML
document containing the message.
So am I missing something?
If not, maybe StatusFilter should be updated to include the Status description?
Thanks!
Avi
Avi Flax » Partner » Arc90 » http://arc90.com
Kindling: Innovation through Collaboration » http://kindlingapp.com
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2649905