Skip to content

Commit

Permalink
re-introduce source error for HttpProxyError
Browse files Browse the repository at this point in the history
to allow non-io-errors to still slip through
  • Loading branch information
GlenDC committed Nov 8, 2024
1 parent e8b083b commit 35d0084
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,21 @@ impl From<std::io::Error> for HttpProxyError {
}
}

// [`HttProxyError`] is acting as the real source,
// as otherwise generic I/O (transport) errors would
// be returned instead of the fact that it's really
// an http proxy error
impl std::error::Error for HttpProxyError {}
impl std::error::Error for HttpProxyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
HttpProxyError::AuthRequired => None,
HttpProxyError::Unavailable => None,
HttpProxyError::Transport(err) => err.source().and_then(|err| {
// filter out generic io errors,
// but do allow custom errors (e.g. because IP is blocked)
if err.is::<std::io::Error>() {
None
} else {
Some(err)
}
}),
HttpProxyError::Other(_) => None,
}
}
}

0 comments on commit 35d0084

Please sign in to comment.