Remove status methods on Response. (#258)

Now that Responses with non-2xx statuses get turned into `Error`,
there is less need for these. Also, surveying the set of public crates
that depend on ureq, none of them use these methods. It seems that
users tend to prefer checking the status code directly.

Here is my thinking on each of these individually:

.ok() -- With the new Result API, any Request you get back will be
.ok(). Also, I think the name .ok() is a little confusing with
Result::ok().

.error() - with the new Result API, this is an exact overlap with
anything that would return Error. People will just check for whether a
Result is Err(...) rather than call .error().

.client_error() - most of the time, if someone wants to specially handle
a 4xx error, they want to handle specific ones, because the response to
them is different. For instance a specialized response to a 404 would be
"delete this from the list of URLs to check in the future," where a
specialized response to a 401 would be "try and load updated
credentials." For instance:

4200edb9ed/healthchecks/src/manage.rs (L70-L84)

75d4b363b6/src/lib.rs (L59-L63)

1d7daea38b/src/netlify.rs (L101-L112)

.server_error() - I don't have as much objection to this one, since it's
reasonable to want to treat all server errors (500, 502, 503) more or
less the same. Although even at that, 501 Not Implemented seems like
people would want to handle it differently. I guess that doesn't come up
much in practice - I've never seen a 501 in the wild.

.redirect() - Usually redirects are handled under the hood, unless
someone disables automatic redirect handling. I'm not terribly opposed
to this one, but given that no-one's using it and it's just as easy to
do 300..399.contains(resp.status()), I'm mildly inclined towards
deletion.
This commit is contained in:
Jacob Hoffman-Andrews
2020-12-05 11:32:25 -08:00
committed by GitHub
parent 5aff777f1f
commit c3a6f50dbe
4 changed files with 2 additions and 27 deletions

View File

@@ -175,7 +175,6 @@ pub fn no_status_text() {
test::make_response(200, "", vec![], vec![])
});
let resp = get("test://host/no_status_text").call().unwrap();
assert!(resp.ok());
assert_eq!(resp.status(), 200);
}