Skip to content

Commit 742d680

Browse files
committed
Drop enum, use DenoError
1 parent 9da5589 commit 742d680

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

src/http.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ pub fn get_client() -> Client<Connector, hyper::Body> {
2929
Client::builder().build(c)
3030
}
3131

32-
enum HyperOrIOError {
33-
IO(io::Error),
34-
Hyper(hyper::Error),
35-
}
36-
3732
fn response_future(
3833
response: hyper::Response<hyper::Body>,
39-
) -> impl Future<Item = String, Error = HyperOrIOError> {
34+
) -> impl Future<Item = String, Error = DenoError> {
4035
if !response.status().is_success() {
41-
return Either::A(futures::future::err(HyperOrIOError::IO(io::Error::new(
36+
return Either::A(futures::future::err(DenoError::from(io::Error::new(
4237
io::ErrorKind::NotFound,
4338
format!("module not found"),
4439
))));
@@ -48,7 +43,7 @@ fn response_future(
4843
.into_body()
4944
.concat2()
5045
.map(|body| String::from_utf8(body.to_vec()).unwrap())
51-
.map_err(|err| HyperOrIOError::Hyper(err)),
46+
.map_err(|err| DenoError::from(err)),
5247
)
5348
}
5449

@@ -59,13 +54,9 @@ pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> {
5954
let client = get_client();
6055
let fetch_future = client
6156
.get(url)
62-
.map_err(|err| HyperOrIOError::Hyper(err))
57+
.map_err(|err| DenoError::from(err))
6358
.and_then(response_future);
64-
match tokio_util::block_on(fetch_future) {
65-
Ok(s) => Ok(s),
66-
Err(HyperOrIOError::Hyper(err)) => Err(DenoError::from(err)),
67-
Err(HyperOrIOError::IO(err)) => Err(DenoError::from(err)),
68-
}
59+
tokio_util::block_on(fetch_future)
6960
}
7061

7162
/* TODO(ry) Re-enabled this test. Disabling to work around bug in #782.

0 commit comments

Comments
 (0)