diff options
author | Yusuke Tanaka <yusuktan@maguro.dev> | 2024-08-08 15:18:33 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-07 23:18:33 -0700 |
commit | 4e4c96bf66111c6e8ba976ed24594edf7abfcbfb (patch) | |
tree | 3fc2f08999df8726bd53578443556c4a0fec42b7 /cli/http_util.rs | |
parent | 9d6da1036d80a29862f6bdfb51e6f51eee235c35 (diff) |
fix(ext/fetch): include URL and error details on fetch failures (#24910)
This commit improves error messages that `fetch` generates on failure.
Fixes #24835
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r-- | cli/http_util.rs | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index b47e91c70..9ec90dd61 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -390,10 +390,10 @@ impl HttpClient { let response = match self.client.clone().send(request).await { Ok(resp) => resp, Err(err) => { - if is_error_connect(&err) { + if err.is_connect_error() { return Ok(FetchOnceResult::RequestError(err.to_string())); } - return Err(err); + return Err(err.into()); } }; @@ -531,7 +531,7 @@ impl HttpClient { .clone() .send(req) .await - .map_err(DownloadError::Fetch)?; + .map_err(|e| DownloadError::Fetch(e.into()))?; let status = response.status(); if status.is_redirection() { for _ in 0..5 { @@ -551,7 +551,7 @@ impl HttpClient { .clone() .send(req) .await - .map_err(DownloadError::Fetch)?; + .map_err(|e| DownloadError::Fetch(e.into()))?; let status = new_response.status(); if status.is_redirection() { response = new_response; @@ -567,13 +567,6 @@ impl HttpClient { } } -fn is_error_connect(err: &AnyError) -> bool { - err - .downcast_ref::<hyper_util::client::legacy::Error>() - .map(|err| err.is_connect()) - .unwrap_or(false) -} - async fn get_response_body_with_progress( response: http::Response<deno_fetch::ResBody>, progress_guard: Option<&UpdateGuard>, @@ -685,7 +678,7 @@ impl RequestBuilder { pub async fn send( self, ) -> Result<http::Response<deno_fetch::ResBody>, AnyError> { - self.client.send(self.req).await + self.client.send(self.req).await.map_err(Into::into) } pub fn build(self) -> http::Request<deno_fetch::ReqBody> { |