From e0cd391bac7207b90f9dbf1a0b97f87c45847362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Tue, 2 Apr 2024 19:48:03 +0300 Subject: [PATCH] fix(eth): error handling in RPCs (#2090) Previously, encountering an error on any type of request, even if it was invalid, would result in a failure due to not being able to find a live RPC client error. This is obviously not correct, and this commit fixes this by returning the correct errors. --- mm2src/coins/eth/eth_rpc.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm2src/coins/eth/eth_rpc.rs b/mm2src/coins/eth/eth_rpc.rs index 36b2c3221c..922e219fbd 100644 --- a/mm2src/coins/eth/eth_rpc.rs +++ b/mm2src/coins/eth/eth_rpc.rs @@ -18,6 +18,7 @@ impl EthCoin { async fn try_rpc_send(&self, method: &str, params: Vec) -> Result { let mut clients = self.web3_instances.lock().await; + let mut error = web3::Error::Unreachable; for (i, client) in clients.clone().into_iter().enumerate() { let execute_fut = match client.web3.transport() { Web3Transport::Http(http) => http.execute(method, params.clone()), @@ -35,8 +36,9 @@ impl EthCoin { clients.rotate_left(i); return Ok(r); }, - Ok(Err(rpc_error)) => { - debug!("Request on '{method}' failed. Error: {rpc_error}"); + Ok(Err(err)) => { + debug!("Request on '{method}' failed. Error: {err}"); + error = err; if let Web3Transport::Websocket(socket_transport) = client.web3.transport() { socket_transport.stop_connection_loop().await; @@ -52,9 +54,7 @@ impl EthCoin { }; } - Err(web3::Error::Transport(web3::error::TransportError::Message(format!( - "Request '{method}' failed due to not being able to find a living RPC client" - )))) + Err(error) } }