Thierry,

I'm fine with the design choice. I stumbled across a place where this wasn't happening [1] but it was hard to associate a HTTP status code with the failure since the request failed to leave the client. Currently I have patched it to set the following status code

response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);

Any thoughts?


[1] http://restlet.tigris.org/servlets/ReadMsg?list=discuss&msgNo=2176


Thierry Boileau wrote:
Adam,

I just want to explain why this behaviour happens, not to plainly justify it. As you point, it has been decided to show the failures by the way of the status code and not by the way of the exceptions. One reason is that for example, the connectors are based on other externals projects that may throw exceptions of different nature even for equivalent issues, and the connectors may throw themselves distinct exceptions for equivalent issues (equivalent from the API's point of view). Then, it has seemed difficult to potentially have to catch a growing list of distinct exceptions in some part of the code (not the whole code, of course). Thus, it has been decided, and it's a design choice, to use the status codes instead of the exceptions.
However, this behaviour may be updated, the discussion is open.

best regards,
Thierry Boileau

Oops, didn't see your reply here.  I just replied to your other thread.

Actually, I disagree.  I think the problem is that the method should
have originally been defined to through checked exceptions.

I want to be to notify the user of the exceptions inside of the client
itself.  If my end user has entered a bad url, then I want to be able to
notify them about that, for example.

Setting a status code is not the way to handle this.  You propose status
code 404, but that's not an appropriate response for a "host not found"
type of problem.  Likewise, it's also not an appropriate status code if
the url itself was poorly formed (like, without a leading protocol scheme).

Anyway, my point is, there are many reason which a request could fail.
I want to see these in my own code so that I can do what's appropriate
with the exception.

Adam


Jim Alateras wrote:
Adam,

I came across the same problem and I believe the problem is more around not setting the response status code on failure.

cheers
</jima>

Adam Taft wrote:

Here's a test case to look at...

public class TestClass {
        public static void main(String[] args) {
               try {
Request request = new Request(Method.GET, "aaaaaaaaaaaaaaaaa");
            Client client = new Client(Protocol.HTTP);
            client.handle(request);
                       System.out.println("This code shouldn't run!");
                   } catch (Throwable t) {
            // eat everything
        }
           }
}

The offending code is in HttpClientHelper#handle ...

    public void handle(Request request, Response response) {
        try {
HttpClientCall httpCall = getConverter().toSpecific(this, request);
            getConverter().commit(httpCall, request, response);
        } catch (Exception e) {
            getLogger().log(Level.WARNING,
                    "Error while handling an HTTP client call: ",
                    e.getMessage());
            getLogger().log(Level.INFO,
                    "Error while handling an HTTP client call", e);
        }
    }


As soon as I get my email confirmation from tigris, I'll file a bug report. I just wanted to mention this in case there are other areas you know about with similar code. If the goal is to log the exception, that's ok, but it needs to be re-thrown.

Thanks!

Adam



Reply via email to