rename error_for_status -> error_on_non_2xx

This commit is contained in:
Martin Algesten
2020-11-15 10:54:10 +01:00
parent d4af920b53
commit f652a9e449

View File

@@ -31,7 +31,7 @@ pub struct Request {
agent: Agent, agent: Agent,
method: String, method: String,
url: String, url: String,
return_error_for_status: bool, error_on_non_2xx: bool,
headers: Vec<Header>, headers: Vec<Header>,
query_params: Vec<(String, String)>, query_params: Vec<(String, String)>,
} }
@@ -53,7 +53,7 @@ impl Request {
method, method,
url, url,
headers: vec![], headers: vec![],
return_error_for_status: true, error_on_non_2xx: true,
query_params: vec![], query_params: vec![],
} }
} }
@@ -87,7 +87,7 @@ impl Request {
let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader); let unit = Unit::new(&self.agent, &self.method, &url, &self.headers, &reader);
let response = unit::connect(unit, true, 0, reader, false)?; let response = unit::connect(unit, true, 0, reader, false)?;
if response.error() && self.return_error_for_status { if response.error() && self.error_on_non_2xx {
Err(Error::HTTP(response.into())) Err(Error::HTTP(response.into()))
} else { } else {
Ok(response) Ok(response)
@@ -305,22 +305,22 @@ impl Request {
} }
/// By default, if a response's status is anything but a 2xx or 3xx, /// By default, if a response's status is anything but a 2xx or 3xx,
/// send() and related methods will return an Error. If you want /// call()/send() and related methods will return an Error. If you want
/// to handle such responses as non-errors, set this to false. /// to handle such responses as non-errors, set this to `false`.
/// ///
/// Example: /// Example:
/// ``` /// ```
/// # fn main() -> Result<(), ureq::Error> { /// # fn main() -> Result<(), ureq::Error> {
/// # ureq::is_test(true); /// # ureq::is_test(true);
/// let response = ureq::get("http://httpbin.org/status/500") /// let response = ureq::get("http://httpbin.org/status/500")
/// .error_for_status(false) /// .error_on_non_2xx(false)
/// .call()?; /// .call()?;
/// assert_eq!(response.status(), 500); /// assert_eq!(response.status(), 500);
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
pub fn error_for_status(mut self, value: bool) -> Self { pub fn error_on_non_2xx(mut self, value: bool) -> Self {
self.return_error_for_status = value; self.error_on_non_2xx = value;
self self
} }
} }