@@ -40,17 +40,21 @@ impl From<io::Error> for BlockSourceError {
4040/// Conversion from `HttpClientError` into `BlockSourceError`.
4141impl From < HttpClientError > for BlockSourceError {
4242 fn from ( e : HttpClientError ) -> BlockSourceError {
43- match & e {
43+ match e {
4444 // Transport errors (connection, timeout, etc.) are transient
45- HttpClientError :: Transport ( _) => BlockSourceError :: transient ( e) ,
46- // HTTP non-2xx errors are transient - e.g. "not found" must not stop polling
47- HttpClientError :: Http ( _) => BlockSourceError :: transient ( e) ,
48- // I/O errors follow the same logic as std::io::Error
49- HttpClientError :: Io ( io_error) => match io_error. kind ( ) {
50- io:: ErrorKind :: InvalidData => BlockSourceError :: persistent ( e) ,
51- io:: ErrorKind :: InvalidInput => BlockSourceError :: persistent ( e) ,
52- _ => BlockSourceError :: transient ( e) ,
45+ HttpClientError :: Transport ( err) => {
46+ BlockSourceError :: transient ( HttpClientError :: Transport ( err) )
5347 } ,
48+ // 5xx errors are transient (server issues), others are persistent (client errors)
49+ HttpClientError :: Http ( http_err) => {
50+ if ( 500 ..600 ) . contains ( & http_err. status_code ) {
51+ BlockSourceError :: transient ( HttpClientError :: Http ( http_err) )
52+ } else {
53+ BlockSourceError :: persistent ( HttpClientError :: Http ( http_err) )
54+ }
55+ } ,
56+ // Delegate to existing From<io::Error> implementation
57+ HttpClientError :: Io ( io_err) => BlockSourceError :: from ( io_err) ,
5458 }
5559 }
5660}
@@ -59,22 +63,36 @@ impl From<HttpClientError> for BlockSourceError {
5963#[ cfg( feature = "rpc-client" ) ]
6064impl From < RpcClientError > for BlockSourceError {
6165 fn from ( e : RpcClientError ) -> BlockSourceError {
62- match & e {
63- RpcClientError :: Http ( http_error) => match http_error {
64- HttpClientError :: Transport ( _) => BlockSourceError :: transient ( e) ,
65- // HTTP non-2xx errors are transient
66- HttpClientError :: Http ( _) => BlockSourceError :: transient ( e) ,
67- HttpClientError :: Io ( io_error) => match io_error. kind ( ) {
68- io:: ErrorKind :: InvalidData => BlockSourceError :: persistent ( e) ,
69- io:: ErrorKind :: InvalidInput => BlockSourceError :: persistent ( e) ,
70- _ => BlockSourceError :: transient ( e) ,
66+ match e {
67+ RpcClientError :: Http ( http_err) => match http_err {
68+ // Transport errors (connection, timeout, etc.) are transient
69+ HttpClientError :: Transport ( err) => {
70+ BlockSourceError :: transient ( RpcClientError :: Http ( HttpClientError :: Transport (
71+ err,
72+ ) ) )
73+ } ,
74+ // 5xx errors are transient (server issues), others are persistent (client errors)
75+ HttpClientError :: Http ( http) => {
76+ if ( 500 ..600 ) . contains ( & http. status_code ) {
77+ BlockSourceError :: transient ( RpcClientError :: Http ( HttpClientError :: Http (
78+ http,
79+ ) ) )
80+ } else {
81+ BlockSourceError :: persistent ( RpcClientError :: Http ( HttpClientError :: Http (
82+ http,
83+ ) ) )
84+ }
7185 } ,
86+ HttpClientError :: Io ( io_err) => BlockSourceError :: from ( io_err) ,
87+ } ,
88+ // RPC errors (e.g. "block not found") are transient
89+ RpcClientError :: Rpc ( rpc_err) => {
90+ BlockSourceError :: transient ( RpcClientError :: Rpc ( rpc_err) )
7291 } ,
73- // RPC errors are transient
74- // e.g. "block not found" should not stop polling
75- RpcClientError :: Rpc ( _) => BlockSourceError :: transient ( e) ,
7692 // Malformed response data is persistent
77- RpcClientError :: InvalidData ( _) => BlockSourceError :: persistent ( e) ,
93+ RpcClientError :: InvalidData ( msg) => {
94+ BlockSourceError :: persistent ( RpcClientError :: InvalidData ( msg) )
95+ } ,
7896 }
7997 }
8098}
0 commit comments