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:
@@ -121,7 +121,7 @@ impl Request {
|
|||||||
let response =
|
let response =
|
||||||
unit::connect(unit, true, 0, reader, false).map_err(|e| e.url(url.clone()))?;
|
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))
|
Err(Error::Status(response.status(), response))
|
||||||
} else {
|
} else {
|
||||||
Ok(response)
|
Ok(response)
|
||||||
@@ -337,26 +337,6 @@ impl Request {
|
|||||||
.push((param.to_string(), value.to_string()));
|
.push((param.to_string(), value.to_string()));
|
||||||
self
|
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]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user