Remove error_on_non_2xx.

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.
This commit is contained in:
Jacob Hoffman-Andrews
2020-12-05 14:05:15 -08:00
parent ec04eef7bc
commit 9e270c77e8

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 self.error_on_non_2xx && response.status() >= 400 {
if response.status() >= 400 {
Err(Error::Status(response.status(), response))
} else {
Ok(response)
@@ -337,26 +337,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]