Skip to content

Commit

Permalink
Drop enum, use DenoError
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Oct 1, 2018
1 parent 9da5589 commit 742d680
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ pub fn get_client() -> Client<Connector, hyper::Body> {
Client::builder().build(c)
}

enum HyperOrIOError {
IO(io::Error),
Hyper(hyper::Error),
}

fn response_future(
response: hyper::Response<hyper::Body>,
) -> impl Future<Item = String, Error = HyperOrIOError> {
) -> impl Future<Item = String, Error = DenoError> {
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"),
))));
Expand All @@ -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)),
)
}

Expand All @@ -59,13 +54,9 @@ pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> {
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.
Expand Down

0 comments on commit 742d680

Please sign in to comment.