Skip to content

Commit

Permalink
catch tcp proxy connect errors as http proxy error
Browse files Browse the repository at this point in the history
these were previously not yet labeled correctly
GlenDC committed Nov 8, 2024
1 parent 932086e commit c83bf92
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::fmt;

use rama_core::error::BoxError;

#[derive(Debug)]
/// error that can be returned in case a http proxy
/// did not manage to establish a connection
@@ -15,7 +17,7 @@ pub enum HttpProxyError {
/// I/O error happened as part of HTTP Proxy Connection Establishment
///
/// (e.g. some kind of TCP error)
Transport(std::io::Error),
Transport(BoxError),
/// Something went wrong, but classification did not happen.
///
/// (First header line of http response is included in error)
@@ -43,17 +45,12 @@ impl fmt::Display for HttpProxyError {

impl From<std::io::Error> for HttpProxyError {
fn from(value: std::io::Error) -> Self {
Self::Transport(value)
Self::Transport(value.into())
}
}

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,
}
}
}
// [`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 {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::client::proxy::layer::HttpProxyError;

use super::InnerHttpProxyConnector;
use rama_core::{
error::{BoxError, ErrorExt, OpaqueError},
@@ -119,9 +121,14 @@ where
.connect(ctx, req)
.await
.map_err(|err| match address.as_ref() {
Some(address) => OpaqueError::from_boxed(err.into()).context(format!(
"establish connection to proxy {} (protocol: {:?})",
address.authority, address.protocol
Some(address) => OpaqueError::from_std(HttpProxyError::Transport(
OpaqueError::from_display(format!(
"establish connection to proxy {} (protocol: {:?}): {}",
address.authority,
address.protocol,
err.into(),
))
.into_boxed(),
)),
None => {
OpaqueError::from_boxed(err.into()).context("establish connection target")

0 comments on commit c83bf92

Please sign in to comment.