From acaf449a4c008685981f57e20a05386ed875338c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 8 Nov 2020 14:13:03 -0500 Subject: [PATCH 1/3] Allow getting the error from a response (#214) This is an alternative to https://github.com/algesten/ureq/pull/132 which does not require breaking changes. Closes https://github.com/algesten/ureq/issues/126. --- src/response.rs | 26 +++++++++++++++++++++++--- src/unit.rs | 2 +- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/response.rs b/src/response.rs index 75ba391..ae2aedf 100644 --- a/src/response.rs +++ b/src/response.rs @@ -213,14 +213,34 @@ impl Response { self.error.is_some() } - /// Get the actual underlying error when the response is + /// Get a reference to the actual underlying error when the response is /// ["synthetic"](struct.Response.html#method.synthetic). pub fn synthetic_error(&self) -> &Option { &self.error } - // Internal-only API, to allow unit::connect to return early on errors. - pub(crate) fn into_error(self) -> Option { + /// Get the actual underlying error when the response is + /// ["synthetic"](struct.Response.html#method.synthetic). + /// + /// This consumes the Response and it cannot be used again. + /// + /// # Example + /// + /// ``` + /// // hold onto the error even after dropping the response + /// let err = { + /// // scheme that this library doesn't understand + /// let resp = ureq::get("borkedscheme://www.example.com").call(); + /// + /// // it's a synthetic error + /// assert!(resp.error() && resp.synthetic()); + /// + /// // resp is dropped here, but the error lives on + /// resp.into_synthetic_error() + /// }; + /// println!("{}", err.unwrap()); + /// ``` + pub fn into_synthetic_error(self) -> Option { self.error } diff --git a/src/unit.rs b/src/unit.rs index 2957af1..1f0c43c 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -199,7 +199,7 @@ pub(crate) fn connect( return connect(req, unit, false, redirect_count, empty, redir); } // Non-retryable errors return early. - return Err(resp.into_error().unwrap()); + return Err(resp.into_synthetic_error().unwrap()); } // squirrel away cookies From 310c14d601ca50a6df9dfeef4ab273a6f8361e18 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 8 Nov 2020 20:40:09 -0800 Subject: [PATCH 2/3] Update CHANGELOG for 1.5.2. (#216) --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 175fa46..3c1c167 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,20 @@ +# 1.5.2 + + * Remove 'static constraint on Request.send(), allowing a wider variety of + types to be passed. Also eliminate some copying. (#205). + * Allow turning a Response into an Error (#214). + * Update env_logger to 0.8.1 (#195). + * Remove convenience method for CONNECT verb (#177). + * Fix bugs in handling of timeout_read (#197 and #198). + # 1.5.1 + * Use cookie_store crate for correct cookie handling (#169). * Fix bug in picking wrong host for redirects introduced in 1.5.0 (#180). * Allow proxy settings on Agent (#178). # 1.5.0 + * Add pluggable name resolution. Users can now override the IP addresses for hostnames of their choice (#148). * bugfix: Don't re-pool streams on drop. This would occur if the user called From c2d4e527a9c1e2572ad7dc01c2532db3f40e2110 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 8 Nov 2020 20:58:11 -0800 Subject: [PATCH 3/3] 1.5.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e449064..bf195fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ureq" -version = "1.5.1" +version = "1.5.2" authors = ["Martin Algesten "] description = "Minimal HTTP request library" license = "MIT/Apache-2.0"