Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
make request error to be confined per request, not a global websocket…
Browse files Browse the repository at this point in the history
… error (#315)
  • Loading branch information
guanqun authored Jun 12, 2021
1 parent f3cddc1 commit 34d38ca
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ethers-providers/src/transports/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct Ws {
requests: mpsc::UnboundedSender<TransportMessage>,
}

type Pending = oneshot::Sender<serde_json::Value>;
type Pending = oneshot::Sender<Result<serde_json::Value, JsonRpcError>>;
type Subscription = mpsc::UnboundedSender<serde_json::Value>;

enum TransportMessage {
Expand Down Expand Up @@ -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)?)
}
Expand Down Expand Up @@ -268,7 +271,7 @@ where
if let Ok(resp) = serde_json::from_str::<Response<serde_json::Value>>(&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) =
Expand All @@ -286,8 +289,8 @@ where
}

// TrySendError is private :(
fn to_client_error<T: ToString>(err: T) -> ClientError {
ClientError::ChannelError(err.to_string())
fn to_client_error<T: Debug>(err: T) -> ClientError {
ClientError::ChannelError(format!("{:?}", err))
}

#[derive(Error, Debug)]
Expand Down

0 comments on commit 34d38ca

Please sign in to comment.