From 742d680c1b0de8f016ff3646b5ddb35fb9f5e4c6 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Mon, 1 Oct 2018 12:23:12 -0700 Subject: [PATCH] Drop enum, use DenoError --- src/http.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/http.rs b/src/http.rs index 985e6dbda7143e..f89f8026f89e79 100644 --- a/src/http.rs +++ b/src/http.rs @@ -29,16 +29,11 @@ pub fn get_client() -> Client { Client::builder().build(c) } -enum HyperOrIOError { - IO(io::Error), - Hyper(hyper::Error), -} - fn response_future( response: hyper::Response, -) -> impl Future { +) -> impl Future { if !response.status().is_success() { - return Either::A(futures::future::err(HyperOrIOError::IO(io::Error::new( + return Either::A(futures::future::err(DenoError::from(io::Error::new( io::ErrorKind::NotFound, format!("module not found"), )))); @@ -48,7 +43,7 @@ fn response_future( .into_body() .concat2() .map(|body| String::from_utf8(body.to_vec()).unwrap()) - .map_err(|err| HyperOrIOError::Hyper(err)), + .map_err(|err| DenoError::from(err)), ) } @@ -59,13 +54,9 @@ pub fn fetch_sync_string(module_name: &str) -> DenoResult { let client = get_client(); let fetch_future = client .get(url) - .map_err(|err| HyperOrIOError::Hyper(err)) + .map_err(|err| DenoError::from(err)) .and_then(response_future); - match tokio_util::block_on(fetch_future) { - Ok(s) => Ok(s), - Err(HyperOrIOError::Hyper(err)) => Err(DenoError::from(err)), - Err(HyperOrIOError::IO(err)) => Err(DenoError::from(err)), - } + tokio_util::block_on(fetch_future) } /* TODO(ry) Re-enabled this test. Disabling to work around bug in #782.