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

@@ -120,7 +120,7 @@ impl Request {
let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader);
let response = unit::connect(unit, true, reader, None).map_err(|e| e.url(url.clone()))?;
if self.error_on_non_2xx && response.status() >= 400 {
if response.status() >= 400 {
Err(Error::Status(response.status(), response))
} else {
Ok(response)
@@ -336,26 +336,6 @@ impl Request {
.push((param.to_string(), value.to_string()));
self
}
/// By default, if a response's status is anything but a 2xx or 3xx,
/// call()/send() and related methods will return an Error. If you want
/// to handle such responses as non-errors, set this to `false`.
///
/// Example:
/// ```
/// # fn main() -> Result<(), ureq::Error> {
/// # ureq::is_test(true);
/// let response = ureq::get("http://httpbin.org/status/500")
/// .error_on_non_2xx(false)
/// .call()?;
/// assert_eq!(response.status(), 500);
/// # Ok(())
/// # }
/// ```
pub fn error_on_non_2xx(mut self, value: bool) -> Self {
self.error_on_non_2xx = value;
self
}
}
#[test]