refactor: reduce number of ErrorKind variants (#3662)

This commit is contained in:
Bartek Iwańczuk 2020-01-20 16:50:16 +01:00 committed by Ry Dahl
parent e83658138b
commit c90036ab88
13 changed files with 61 additions and 224 deletions

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::deno_error::too_many_redirects;
use crate::deno_error::DenoError;
use crate::deno_error::ErrorKind;
use crate::deno_error::GetErrorKind;
@ -107,7 +106,7 @@ impl SourceFileFetcher {
if !SUPPORTED_URL_SCHEMES.contains(&url.scheme()) {
return Err(
DenoError::new(
ErrorKind::UnsupportedFetchScheme,
ErrorKind::Other,
format!("Unsupported scheme \"{}\" for module \"{}\". Supported schemes: {:#?}", url.scheme(), url, SUPPORTED_URL_SCHEMES),
).into()
);
@ -358,7 +357,8 @@ impl SourceFileFetcher {
redirect_limit: i64,
) -> Pin<Box<SourceFileFuture>> {
if redirect_limit < 0 {
return futures::future::err(too_many_redirects()).boxed();
let e = DenoError::new(ErrorKind::Http, "too many redirects".to_string());
return futures::future::err(e.into()).boxed();
}
let is_blacklisted =
@ -1295,7 +1295,7 @@ mod tests {
.map(move |result| {
assert!(result.is_err());
let err = result.err().unwrap();
assert_eq!(err.kind(), ErrorKind::TooManyRedirects);
assert_eq!(err.kind(), ErrorKind::Http);
});
tokio_util::run(fut);
@ -1571,7 +1571,7 @@ mod tests {
SourceFileFetcher::check_if_supported_scheme(&url)
.unwrap_err()
.kind(),
ErrorKind::UnsupportedFetchScheme
ErrorKind::Other
);
}
}