Remove error_on_non_2xx. (#272)

After the recent changes in #257, it's probably not necessary. It's now
quite easy to use a match statement to extract responses for certain
status codes, or all status codes.

Add documentation on how to turn a status code error back into a
Response.
This commit is contained in:
Jacob Hoffman-Andrews
2020-12-18 22:10:55 -08:00
committed by GitHub
7 changed files with 38 additions and 25 deletions

View File

@@ -42,6 +42,23 @@ use crate::Response;
/// ureq::get(url).call()
/// }
/// ```
///
/// If you'd like to treat all status code errors as normal, successful responses,
/// you can use [Result::or_else](std::result::Result::or_else) like this:
///
/// ```
/// use ureq::Error::Status;
/// # fn main() -> std::result::Result<(), ureq::Error> {
/// # ureq::is_test(true);
/// let resp = ureq::get("http://example.com/")
/// .call()
/// .or_else(|e| match e {
/// Status(_, r) => Ok(r), // turn status errors into Ok Responses.
/// _ => Err(e),
/// })?;
/// # Ok(())
/// # }
/// ```
#[derive(Debug)]
pub enum Error {
/// A response was successfully received but had status code >= 400.