From 34d38ca40f22bbfcd97f75217d917e3137a7eeef Mon Sep 17 00:00:00 2001 From: guanqun Date: Sat, 12 Jun 2021 15:46:19 +0800 Subject: [PATCH] make request error to be confined per request, not a global websocket error (#315) --- ethers-providers/src/transports/ws.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ethers-providers/src/transports/ws.rs b/ethers-providers/src/transports/ws.rs index b1cd37ce..f8f1c2c8 100644 --- a/ethers-providers/src/transports/ws.rs +++ b/ethers-providers/src/transports/ws.rs @@ -43,7 +43,7 @@ pub struct Ws { requests: mpsc::UnboundedSender, } -type Pending = oneshot::Sender; +type Pending = oneshot::Sender>; type Subscription = mpsc::UnboundedSender; enum TransportMessage { @@ -129,6 +129,9 @@ impl JsonRpcClient for Ws { // wait for the response let res = receiver.await?; + // in case the request itself has any errors + let res = res?; + // parse it Ok(serde_json::from_value(res)?) } @@ -268,7 +271,7 @@ where if let Ok(resp) = serde_json::from_str::>(&inner) { if let Some(request) = self.pending.remove(&resp.id) { request - .send(resp.data.into_result()?) + .send(resp.data.into_result()) .map_err(to_client_error)?; } } else if let Ok(notification) = @@ -286,8 +289,8 @@ where } // TrySendError is private :( -fn to_client_error(err: T) -> ClientError { - ClientError::ChannelError(err.to_string()) +fn to_client_error(err: T) -> ClientError { + ClientError::ChannelError(format!("{:?}", err)) } #[derive(Error, Debug)]