Exceptions for standard http code responses #37

dominicfarr opened this Issue Jun 26, 2014 · 0 comments


None yet
1 participant

dominicfarr commented Jun 26, 2014

I find the use of Exceptions incorrect.

For example,

JSONResource jsonResource = resty.json(url);

If I make a call to an api using the above code and the remote service returns http 404, Resty throws an IOException. This isn't what I expect. It should return to me a JSONResource with a response code 404.

int statusCode = jsonResource.http().getResponseCode();

// statusCode == 404 

404 isn't an exceptional case, it is a standard, expected response from an http call.

Throwing an exception, especially a checked exception, is wrong. Clients need to react differently to 2xx, 3xx, 4xx, and 5xx type response, wrapping every non 2xx http in a checked exception hides important information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment