Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Exceptions for standard http code responses #37

Open
dominicfarr opened this issue Jun 26, 2014 · 0 comments
Open

Exceptions for standard http code responses #37

dominicfarr opened this issue Jun 26, 2014 · 0 comments

Comments

@dominicfarr
Copy link
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant