Resty
Resty copied to clipboard
Exceptions for standard http code responses
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.