Skip to content

Commit

Permalink
fix(eth): error handling in RPCs (#2090)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
onur-ozkan authored Apr 2, 2024
1 parent a81a67f commit e0cd391
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mm2src/coins/eth/eth_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl EthCoin {
async fn try_rpc_send(&self, method: &str, params: Vec<jsonrpc_core::Value>) -> Result<Value, web3::Error> {
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()),
Expand All @@ -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;
Expand All @@ -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)
}
}

Expand Down

0 comments on commit e0cd391

Please sign in to comment.