-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
classify known http proxy connect errors
makes it easier for downstream users to classify these into something specific
- Loading branch information
Showing
4 changed files
with
82 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
rama-http-backend/src/client/proxy/layer/proxy_connector/proxy_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
/// error that can be returned in case a http proxy | ||
/// did not manage to establish a connection | ||
pub enum HttpProxyError { | ||
/// Proxy Authentication Required | ||
/// | ||
/// (Proxy returned HTTP 407) | ||
AuthRequired, | ||
/// Proxy is Unavailable | ||
/// | ||
/// (Proxy returned HTTP 503) | ||
Unavailable, | ||
/// I/O error happened as part of HTTP Proxy Connection Establishment | ||
/// | ||
/// (e.g. some kind of TCP error) | ||
Transport(std::io::Error), | ||
/// Something went wrong, but classification did not happen. | ||
/// | ||
/// (First header line of http response is included in error) | ||
Other(String), | ||
} | ||
|
||
impl fmt::Display for HttpProxyError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
HttpProxyError::AuthRequired => { | ||
write!(f, "http proxy error: proxy auth required (http 407)") | ||
} | ||
HttpProxyError::Unavailable => { | ||
write!(f, "http proxy error: proxy unavailable (http 503)") | ||
} | ||
HttpProxyError::Transport(error) => { | ||
write!(f, "http proxy error: transport error: I/O [{}]", error) | ||
} | ||
HttpProxyError::Other(header) => { | ||
write!(f, "http proxy error: first line of header = [{}]", header) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for HttpProxyError { | ||
fn from(value: std::io::Error) -> Self { | ||
Self::Transport(value) | ||
} | ||
} | ||
|
||
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) => Some(err), | ||
HttpProxyError::Other(_) => None, | ||
} | ||
} | ||
} |