Refactor connect errors to not use io::Error (#782)

This commit is contained in:
Sean McArthur
2020-01-13 13:29:14 -08:00
committed by GitHub
parent 14908ad3f0
commit e31d5221fe
2 changed files with 48 additions and 38 deletions

View File

@@ -82,7 +82,16 @@ impl Error {
/// Returns true if the error is related to a timeout.
pub fn is_timeout(&self) -> bool {
self.source().map(|e| e.is::<TimedOut>()).unwrap_or(false)
let mut source = self.source();
while let Some(err) = source {
if err.is::<TimedOut>() {
return true;
}
source = err.source();
}
false
}
/// Returns the status code, if the error was generated from a response.
@@ -309,4 +318,14 @@ mod tests {
_ => panic!("{:?}", err),
}
}
#[test]
fn is_timeout() {
let err = super::request(super::TimedOut);
assert!(err.is_timeout());
let io = io::Error::new(io::ErrorKind::Other, err);
let nested = super::request(io);
assert!(nested.is_timeout());
}
}