From d0052ccfb53b891859a37e10f8e09193ef0d5b17 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 10 May 2022 21:44:33 -0700 Subject: [PATCH] Avoid panic when trying to fetch an invalid URL --- crates/client/src/http.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/client/src/http.rs b/crates/client/src/http.rs index 4dbc9b629a..7f4cafa17d 100644 --- a/crates/client/src/http.rs +++ b/crates/client/src/http.rs @@ -8,6 +8,7 @@ pub use isahc::{ http::{Method, Uri}, Error, }; +use smol::future::FutureExt; use std::sync::Arc; pub use url::Url; @@ -23,18 +24,19 @@ pub trait HttpClient: Send + Sync { body: AsyncBody, follow_redirects: bool, ) -> BoxFuture<'a, Result> { - self.send( - isahc::Request::builder() - .redirect_policy(if follow_redirects { - RedirectPolicy::Follow - } else { - RedirectPolicy::None - }) - .method(Method::GET) - .uri(uri) - .body(body) - .unwrap(), - ) + let request = isahc::Request::builder() + .redirect_policy(if follow_redirects { + RedirectPolicy::Follow + } else { + RedirectPolicy::None + }) + .method(Method::GET) + .uri(uri) + .body(body); + match request { + Ok(request) => self.send(request), + Err(error) => async move { Err(error.into()) }.boxed(), + } } }