diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-09-14 18:48:57 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-09-15 01:50:52 +0200 |
commit | f5b40c918c7d602827622d167728a3e7bae87d9d (patch) | |
tree | fb51722e043f4d6bce64a2c7e897cce4ead06c82 /cli/http_util.rs | |
parent | 3da20d19a14ab6838897d281f1b11e49d68bd1a7 (diff) |
refactor: use the 'anyhow' crate instead of 'ErrBox' (#7476)
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r-- | cli/http_util.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index 8436b600b..015bfaa46 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -2,7 +2,8 @@ use crate::version; use bytes::Bytes; -use deno_core::ErrBox; +use deno_core::error::generic_error; +use deno_core::error::AnyError; use reqwest::header::HeaderMap; use reqwest::header::HeaderValue; use reqwest::header::IF_NONE_MATCH; @@ -26,7 +27,7 @@ use url::Url; /// Create new instance of async reqwest::Client. This client supports /// proxies and doesn't follow redirects. -pub fn create_http_client(ca_file: Option<&str>) -> Result<Client, ErrBox> { +pub fn create_http_client(ca_file: Option<&str>) -> Result<Client, AnyError> { let mut headers = HeaderMap::new(); headers.insert( USER_AGENT, @@ -46,7 +47,7 @@ pub fn create_http_client(ca_file: Option<&str>) -> Result<Client, ErrBox> { builder .build() - .map_err(|_| ErrBox::error("Unable to build http client")) + .map_err(|_| generic_error("Unable to build http client")) } /// Construct the next uri based on base uri and location header fragment /// See <https://tools.ietf.org/html/rfc3986#section-4.2> @@ -96,7 +97,7 @@ pub async fn fetch_once( client: Client, url: &Url, cached_etag: Option<String>, -) -> Result<FetchOnceResult, ErrBox> { +) -> Result<FetchOnceResult, AnyError> { let url = url.clone(); let mut request = client.get(url.clone()); @@ -140,7 +141,7 @@ pub async fn fetch_once( let new_url = resolve_url_from_location(&url, location_string); return Ok(FetchOnceResult::Redirect(new_url, headers_)); } else { - return Err(ErrBox::error(format!( + return Err(generic_error(format!( "Redirection from '{}' did not provide location header", url ))); @@ -150,7 +151,7 @@ pub async fn fetch_once( if response.status().is_client_error() || response.status().is_server_error() { let err = - ErrBox::error(format!("Import '{}' failed: {}", &url, response.status())); + generic_error(format!("Import '{}' failed: {}", &url, response.status())); return Err(err); } |