summaryrefslogtreecommitdiff
path: root/runtime/errors.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-07-18 00:37:31 +0100
committerGitHub <noreply@github.com>2024-07-18 01:37:31 +0200
commit7b33623b1d70803b43e511a58666a73dd0b2ed67 (patch)
tree2d900f2be67caebf6a886d6e06a340b095e636cc /runtime/errors.rs
parentf4b9d8586215fc07c28998e5d896fefa876139b7 (diff)
Reland "refactor(fetch): reimplement fetch with hyper instead of reqwest" (#24593)
Originally landed in https://github.com/denoland/deno/commit/f6fd6619e708a515831f707438368d81b0c9aa56. Reverted in https://github.com/denoland/deno/pull/24574. This reland contains a fix that sends "Accept: */*" header for calls made from "FileFetcher". Absence of this header made downloading source code from JSR broken. This is tested by ensuring this header is present in the test server that servers JSR packages. --------- Co-authored-by: Sean McArthur <sean@seanmonstar.com>
Diffstat (limited to 'runtime/errors.rs')
-rw-r--r--runtime/errors.rs47
1 files changed, 18 insertions, 29 deletions
diff --git a/runtime/errors.rs b/runtime/errors.rs
index 7f2e49250..694402773 100644
--- a/runtime/errors.rs
+++ b/runtime/errors.rs
@@ -13,7 +13,6 @@ use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::url;
use deno_core::ModuleResolutionError;
-use deno_fetch::reqwest;
use std::env;
use std::error::Error;
use std::io;
@@ -101,27 +100,6 @@ fn get_regex_error_class(error: &regex::Error) -> &'static str {
}
}
-fn get_request_error_class(error: &reqwest::Error) -> &'static str {
- error
- .source()
- .and_then(|inner_err| {
- (inner_err
- .downcast_ref::<io::Error>()
- .map(get_io_error_class))
- .or_else(|| {
- inner_err
- .downcast_ref::<serde_json::error::Error>()
- .map(get_serde_json_error_class)
- })
- .or_else(|| {
- inner_err
- .downcast_ref::<url::ParseError>()
- .map(get_url_parse_error_class)
- })
- })
- .unwrap_or("Http")
-}
-
fn get_serde_json_error_class(
error: &serde_json::error::Error,
) -> &'static str {
@@ -142,7 +120,17 @@ fn get_url_parse_error_class(_error: &url::ParseError) -> &'static str {
"URIError"
}
-fn get_hyper_error_class(_error: &hyper_v014::Error) -> &'static str {
+fn get_hyper_error_class(_error: &hyper::Error) -> &'static str {
+ "Http"
+}
+
+fn get_hyper_util_error_class(
+ _error: &hyper_util::client::legacy::Error,
+) -> &'static str {
+ "Http"
+}
+
+fn get_hyper_v014_error_class(_error: &hyper_v014::Error) -> &'static str {
"Http"
}
@@ -175,13 +163,18 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
e.downcast_ref::<dlopen2::Error>()
.map(get_dlopen_error_class)
})
+ .or_else(|| e.downcast_ref::<hyper::Error>().map(get_hyper_error_class))
+ .or_else(|| {
+ e.downcast_ref::<hyper_util::client::legacy::Error>()
+ .map(get_hyper_util_error_class)
+ })
.or_else(|| {
e.downcast_ref::<hyper_v014::Error>()
- .map(get_hyper_error_class)
+ .map(get_hyper_v014_error_class)
})
.or_else(|| {
e.downcast_ref::<Arc<hyper_v014::Error>>()
- .map(|e| get_hyper_error_class(e))
+ .map(|e| get_hyper_v014_error_class(e))
})
.or_else(|| {
e.downcast_ref::<deno_core::Canceled>().map(|e| {
@@ -202,10 +195,6 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> {
e.downcast_ref::<notify::Error>()
.map(get_notify_error_class)
})
- .or_else(|| {
- e.downcast_ref::<reqwest::Error>()
- .map(get_request_error_class)
- })
.or_else(|| e.downcast_ref::<regex::Error>().map(get_regex_error_class))
.or_else(|| {
e.downcast_ref::<serde_json::error::Error>()