@@ -3,9 +3,10 @@ use std::{cell::Cell, cell::RefCell, fmt, marker::PhantomData, rc::Rc, time::Dur
33
44use nanorand:: { Rng , WyRand } ;
55use ntex_bytes:: ByteString ;
6+ use ntex_error:: Error ;
67use ntex_http:: { HeaderMap , Method , uri:: Scheme } ;
78use ntex_io:: IoBoxed ;
8- use ntex_net:: connect:: { Address , Connect , ConnectError , Connector as DefaultConnector } ;
9+ use ntex_net:: connect:: { Address , Connect , ConnectError , Connector2 as DefaultConnector } ;
910use ntex_service:: cfg:: { Cfg , SharedCfg } ;
1011use ntex_service:: { IntoServiceFactory , Pipeline , ServiceFactory } ;
1112use ntex_util:: time:: { Millis , Seconds , timeout_checked} ;
@@ -15,8 +16,8 @@ use super::stream::{InflightStorage, RecvStream, SendStream};
1516use super :: { ClientError , simple:: SimpleClient } ;
1617use crate :: ServiceConfig ;
1718
18- type Fut = BoxFuture < ' static , Result < IoBoxed , ConnectError > > ;
19- type Connector = Box < dyn Fn ( ) -> BoxFuture < ' static , Result < IoBoxed , ConnectError > > > ;
19+ type Fut = BoxFuture < ' static , Result < IoBoxed , Error < ConnectError > > > ;
20+ type Connector = Box < dyn Fn ( ) -> BoxFuture < ' static , Result < IoBoxed , Error < ConnectError > > > > ;
2021
2122#[ derive( Clone ) ]
2223/// Manages http client network connectivity.
@@ -48,7 +49,7 @@ impl Client {
4849 where
4950 A : Address + Clone ,
5051 F : IntoServiceFactory < T , Connect < A > , SharedCfg > ,
51- T : ServiceFactory < Connect < A > , SharedCfg , Error = ConnectError > + ' static ,
52+ T : ServiceFactory < Connect < A > , SharedCfg , Error = Error < ConnectError > > + ' static ,
5253 IoBoxed : From < T :: Response > ,
5354 Connect < A > : From < U > ,
5455 {
@@ -62,16 +63,16 @@ impl Client {
6263 path : ByteString ,
6364 headers : HeaderMap ,
6465 eof : bool ,
65- ) -> Result < ( SendStream , RecvStream ) , ClientError > {
66+ ) -> Result < ( SendStream , RecvStream ) , Error < ClientError > > {
6667 self . client ( )
6768 . await ?
6869 . send ( method, path, headers, eof)
6970 . await
70- . map_err ( From :: from)
71+ . map_err ( |e| e . map ( ClientError :: from) )
7172 }
7273
7374 /// Get client from the pool
74- pub async fn client ( & self ) -> Result < SimpleClient , ClientError > {
75+ pub async fn client ( & self ) -> Result < SimpleClient , Error < ClientError > > {
7576 loop {
7677 let ( client, num) = self . get_client ( ) ;
7778
@@ -82,7 +83,7 @@ impl Client {
8283 }
8384 }
8485
85- async fn connect ( & self , num : usize ) -> Result < ( ) , ClientError > {
86+ async fn connect ( & self , num : usize ) -> Result < ( ) , Error < ClientError > > {
8687 let cfg = & self . inner . config ;
8788
8889 // can create new connection
@@ -102,7 +103,8 @@ impl Client {
102103 // wait for available connection
103104 let ( tx, rx) = cfg. pool . channel ( ) ;
104105 self . waiters . borrow_mut ( ) . push_back ( tx) ;
105- rx. await ?;
106+ rx. await
107+ . map_err ( |e| Error :: new ( e, self . inner . cfg . service ( ) ) ) ?;
106108 }
107109 Ok ( ( ) )
108110 }
@@ -157,7 +159,7 @@ impl Client {
157159 }
158160 }
159161
160- async fn create_connection ( & self ) -> Result < ( ) , ClientError > {
162+ async fn create_connection ( & self ) -> Result < ( ) , Error < ClientError > > {
161163 let ( tx, rx) = oneshot:: channel ( ) ;
162164
163165 let inner = self . inner . clone ( ) ;
@@ -188,8 +190,8 @@ impl Client {
188190 . set ( inner. config . total_connections . get ( ) + 1 ) ;
189191 Ok ( ( ) )
190192 }
191- Ok ( Err ( err) ) => Err ( ClientError :: from ( err ) ) ,
192- Err ( ( ) ) => Err ( ClientError :: HandshakeTimeout ) ,
193+ Ok ( Err ( err) ) => Err ( err . map ( ClientError :: from) ) ,
194+ Err ( ( ) ) => Err ( Error :: from ( ClientError :: HandshakeTimeout ) ) ,
193195 } ;
194196 inner. config . connecting . set ( false ) ;
195197 for waiter in waiters. borrow_mut ( ) . drain ( ..) {
@@ -205,7 +207,8 @@ impl Client {
205207 let _ = tx. send ( res) ;
206208 } ) ;
207209
208- rx. await ?
210+ rx. await
211+ . map_err ( |e| Error :: new ( e, self . inner . cfg . service ( ) ) ) ?
209212 }
210213
211214 #[ inline]
@@ -298,7 +301,7 @@ struct InnerConfig {
298301impl < A , T > ClientBuilder < A , T >
299302where
300303 A : Address + Clone ,
301- T : ServiceFactory < Connect < A > , SharedCfg , Error = ConnectError > ,
304+ T : ServiceFactory < Connect < A > , SharedCfg , Error = Error < ConnectError > > ,
302305 IoBoxed : From < T :: Response > ,
303306{
304307 fn new < U , F > ( addr : U , connector : F ) -> Self
@@ -412,7 +415,7 @@ where
412415 pub fn connector < U , F > ( self , connector : F ) -> ClientBuilder < A , U >
413416 where
414417 F : IntoServiceFactory < U , Connect < A > , SharedCfg > ,
415- U : ServiceFactory < Connect < A > , SharedCfg , Error = ConnectError > + ' static ,
418+ U : ServiceFactory < Connect < A > , SharedCfg , Error = Error < ConnectError > > + ' static ,
416419 IoBoxed : From < U :: Response > ,
417420 {
418421 ClientBuilder {
@@ -427,7 +430,7 @@ where
427430impl < A , T > ClientBuilder < A , T >
428431where
429432 A : Address + Clone ,
430- T : ServiceFactory < Connect < A > , SharedCfg , Error = ConnectError > + ' static ,
433+ T : ServiceFactory < Connect < A > , SharedCfg , Error = Error < ConnectError > > + ' static ,
431434 IoBoxed : From < T :: Response > ,
432435{
433436 /// Finish configuration process and create connections pool.
0 commit comments