@@ -56,6 +56,8 @@ struct Config {
56
56
pub struct Error {
57
57
kind : ErrorKind ,
58
58
source : Option < Box < dyn StdError + Send + Sync > > ,
59
+ #[ cfg( any( feature = "http1" , feature = "http2" ) ) ]
60
+ connect_info : Option < Connected > ,
59
61
}
60
62
61
63
#[ derive( Debug ) ]
@@ -74,12 +76,14 @@ macro_rules! e {
74
76
Error {
75
77
kind: ErrorKind :: $kind,
76
78
source: None ,
79
+ connect_info: None ,
77
80
}
78
81
} ;
79
82
( $kind: ident, $src: expr) => {
80
83
Error {
81
84
kind: ErrorKind :: $kind,
82
85
source: Some ( $src. into( ) ) ,
86
+ connect_info: None ,
83
87
}
84
88
} ;
85
89
}
@@ -277,7 +281,9 @@ where
277
281
if pooled. is_http1 ( ) {
278
282
if req. version ( ) == Version :: HTTP_2 {
279
283
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
+ ) ) ;
281
287
}
282
288
283
289
if self . config . set_host {
@@ -311,11 +317,15 @@ where
311
317
Err ( mut err) => {
312
318
return if let Some ( req) = err. take_message ( ) {
313
319
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 ( ) ) ,
315
322
req,
316
323
} )
317
324
} 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
+ ) )
319
329
}
320
330
}
321
331
} ;
@@ -789,6 +799,7 @@ impl<B: Body + 'static> PoolClient<B> {
789
799
PoolTx :: Http2 ( ref mut tx) => tx. try_send_request ( req) ,
790
800
} ;
791
801
}
802
+
792
803
/*
793
804
//TODO: can we re-introduce this somehow? Or must people use tower::retry?
794
805
fn send_request_retryable(
@@ -1602,6 +1613,19 @@ impl Error {
1602
1613
matches ! ( self . kind, ErrorKind :: Connect )
1603
1614
}
1604
1615
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
+ }
1605
1629
fn is_canceled ( & self ) -> bool {
1606
1630
matches ! ( self . kind, ErrorKind :: Canceled )
1607
1631
}
0 commit comments