Thanks to visit codestin.com
Credit goes to github.com

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

Exceptions for standard http code responses #37

@dominicfarr

Description

@dominicfarr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions