@@ -18,16 +18,14 @@ pub enum Error {
1818 #[ error( "Operation timed out" ) ]
1919 Timeout ,
2020 #[ error( "RPC call failed after exhausting all retry attempts: {0}" ) ]
21- RetryFailure ( Arc < RpcError < TransportErrorKind > > ) ,
21+ RpcError ( Arc < RpcError < TransportErrorKind > > ) ,
2222 #[ error( "Block not found, Block Id: {0}" ) ]
2323 BlockNotFound ( BlockId ) ,
24- #[ error( "No RPC providers support pubsub" ) ]
25- PubSubNotSupported ,
2624}
2725
2826impl From < RpcError < TransportErrorKind > > for Error {
2927 fn from ( err : RpcError < TransportErrorKind > ) -> Self {
30- Error :: RetryFailure ( Arc :: new ( err) )
28+ Error :: RpcError ( Arc :: new ( err) )
3129 }
3230}
3331
@@ -195,8 +193,11 @@ impl<N: Network> RobustProvider<N> {
195193 /// after exhausting retries or if the call times out.
196194 pub async fn subscribe_blocks ( & self ) -> Result < Subscription < N :: HeaderResponse > , Error > {
197195 info ! ( "eth_subscribe called" ) ;
198- // We need this otherwise error is not clear
199- self . root ( ) . client ( ) . expect_pubsub_frontend ( ) ;
196+
197+ self . root ( ) . client ( ) . pubsub_frontend ( ) . ok_or_else ( || {
198+ Error :: from ( RpcError :: Transport ( TransportErrorKind :: PubsubUnavailable ) )
199+ } ) ?;
200+
200201 let result = self
201202 . retry_with_total_timeout (
202203 move |provider| async move { provider. subscribe_blocks ( ) . await } ,
@@ -366,7 +367,7 @@ mod tests {
366367 } )
367368 . await ;
368369
369- assert ! ( matches!( result, Err ( Error :: RetryFailure ( _) ) ) ) ;
370+ assert ! ( matches!( result, Err ( Error :: RpcError ( _) ) ) ) ;
370371 assert_eq ! ( call_count. load( Ordering :: SeqCst ) , 3 ) ;
371372 }
372373
@@ -389,14 +390,15 @@ mod tests {
389390 async fn test_http_provider_skipped_when_pubsub_required ( ) {
390391 let provider = test_provider ( 100 , 3 , 10 ) ;
391392
392- let result: Result < ( ) , Error > = provider
393- . retry_with_total_timeout (
394- |_| async { Ok ( ( ) ) } ,
395- true , // require pubsub
396- )
397- . await ;
393+ let result = provider. subscribe_blocks ( ) . await ;
394+
395+ let Err ( Error :: RpcError ( err) ) = result else {
396+ panic ! ( "Expected Error::RpcError, got: {result:?}" ) ;
397+ } ;
398398
399- // Should get PubSubNotSupported error
400- assert ! ( matches!( result, Err ( Error :: PubSubNotSupported ) ) ) ;
399+ assert ! (
400+ matches!( err. as_ref( ) , RpcError :: Transport ( TransportErrorKind :: PubsubUnavailable ) ) ,
401+ "Expected PubsubUnavailable error, got: {err:?}" ,
402+ ) ;
401403 }
402404}
0 commit comments