Add Error::{kind, status, into_response}.

Also, remove Response::{ok, error, client_error, server_error,
redirect}. The idea is that you would access these through the
Error object instead.

I fetched all the reverse dependencies of ureq on crates.io and looked
for uses of the methods being removed. I found none.

I'm also considering removing the error_on_non_2xx method entirely. If
it's easy to get the underlying response for errors, it would be nice to
make that the single way to do things rather than support two separate
ways of handling HTTP errors.
This commit is contained in:
Jacob Hoffman-Andrews
2020-11-25 20:15:46 -08:00
committed by Martin Algesten
parent 35c03521b9
commit 4c3b93d86d
5 changed files with 45 additions and 30 deletions

View File

@@ -121,7 +121,7 @@ impl Request {
let response =
unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url.clone()))?;
if response.error() && self.error_on_non_2xx {
if self.error_on_non_2xx && response.status() >= 400 {
Err(ErrorKind::HTTP.new().url(url.clone()).response(response))
} else {
Ok(response)