@@ -56,6 +56,8 @@ struct Config {
5656pub struct Error {
5757 kind : ErrorKind ,
5858 source : Option < Box < dyn StdError + Send + Sync > > ,
59+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
60+ connect_info : Option < Connected > ,
5961}
6062
6163#[ derive( Debug ) ]
@@ -74,12 +76,14 @@ macro_rules! e {
7476 Error {
7577 kind: ErrorKind :: $kind,
7678 source: None ,
79+ connect_info: None ,
7780 }
7881 } ;
7982 ( $kind: ident, $src: expr) => {
8083 Error {
8184 kind: ErrorKind :: $kind,
8285 source: Some ( $src. into( ) ) ,
86+ connect_info: None ,
8387 }
8488 } ;
8589}
@@ -277,7 +281,9 @@ where
277281 if pooled. is_http1 ( ) {
278282 if req. version ( ) == Version :: HTTP_2 {
279283 warn ! ( "Connection is HTTP/1, but request requires HTTP/2" ) ;
280- return Err ( TrySendError :: Nope ( e ! ( UserUnsupportedVersion ) ) ) ;
284+ return Err ( TrySendError :: Nope (
285+ e ! ( UserUnsupportedVersion ) . with_connect_info ( pooled. conn_info . clone ( ) ) ,
286+ ) ) ;
281287 }
282288
283289 if self . config . set_host {
@@ -311,11 +317,15 @@ where
311317 Err ( mut err) => {
312318 return if let Some ( req) = err. take_message ( ) {
313319 Err ( TrySendError :: Retryable {
314- error : e ! ( Canceled , err. into_error( ) ) ,
320+ error : e ! ( Canceled , err. into_error( ) )
321+ . with_connect_info ( pooled. conn_info . clone ( ) ) ,
315322 req,
316323 } )
317324 } else {
318- Err ( TrySendError :: Nope ( e ! ( SendRequest , err. into_error( ) ) ) )
325+ Err ( TrySendError :: Nope (
326+ e ! ( SendRequest , err. into_error( ) )
327+ . with_connect_info ( pooled. conn_info . clone ( ) ) ,
328+ ) )
319329 }
320330 }
321331 } ;
@@ -789,6 +799,7 @@ impl<B: Body + 'static> PoolClient<B> {
789799 PoolTx :: Http2 ( ref mut tx) => tx. try_send_request ( req) ,
790800 } ;
791801 }
802+
792803 /*
793804 //TODO: can we re-introduce this somehow? Or must people use tower::retry?
794805 fn send_request_retryable(
@@ -1602,6 +1613,19 @@ impl Error {
16021613 matches ! ( self . kind, ErrorKind :: Connect )
16031614 }
16041615
1616+ /// Returns the info of the client connection on which this error occurred.
1617+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1618+ pub fn connect_info ( & self ) -> Option < & Connected > {
1619+ self . connect_info . as_ref ( )
1620+ }
1621+
1622+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
1623+ fn with_connect_info ( self , connect_info : Connected ) -> Self {
1624+ Self {
1625+ connect_info : Some ( connect_info) ,
1626+ ..self
1627+ }
1628+ }
16051629 fn is_canceled ( & self ) -> bool {
16061630 matches ! ( self . kind, ErrorKind :: Canceled )
16071631 }
0 commit comments