diff options
author | Vincent Ambo <mail@tazj.in> | 2019-02-26T21·21+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2019-02-26T21·21+0100 |
commit | e4e931661b23d1af41b97df3f17f937cd68cc77e (patch) | |
tree | bf93089359de3c29624e813334c758ad282140b5 /src/tests.rs | |
parent | 481825672ef5396c0c1e10adcad412a34b3488ef (diff) |
feat: Introduce `Response::error_for_status` method
This method makes it possible to let users map responses with unexpected HTTP statuses to custom errors while staying inside a chain of results.
Diffstat (limited to 'src/tests.rs')
-rw-r--r-- | src/tests.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/tests.rs b/src/tests.rs index c240f55ae199..3b7a59cadd77 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -115,3 +115,15 @@ fn test_basic_auth() { assert!(response.is_success(), "authorized request should succeed"); } + +// Tests for various other features. + +#[test] +fn test_error_for_status() { + let response = Request::new(Method::Get, "https://httpbin.org/patch") + .send().expect("failed to send request") + .error_for_status(|resp| format!("Response error code: {}", resp.status)); + + assert_eq!(Err("Response error code: 405".into()), response, + "returned error should be converted into Result::Err"); +} |