Skip to content

Commit 4b66ef5

Browse files
committed
fix: don't wrap rpc error in DisconnectedWillReconnect in reconnecting rpc client (#1904)
* fix: don't wrap rpc err in DisconnectedWillRecon * add clarifying comment * fix no-std-test build * fix no-std-test build v2
1 parent 9640ecc commit 4b66ef5

File tree

3 files changed

+111
-1171
lines changed

3 files changed

+111
-1171
lines changed

subxt/src/backend/rpc/reconnecting_rpc_client/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@ impl RpcClientT for RpcClient {
427427
async {
428428
self.request(method.to_string(), params)
429429
.await
430-
.map_err(|e| SubxtRpcError::DisconnectedWillReconnect(e.to_string()))
430+
.map_err(|e| match e {
431+
Error::DisconnectedWillReconnect(e) => {
432+
SubxtRpcError::DisconnectedWillReconnect(e.to_string())
433+
}
434+
Error::Dropped => SubxtRpcError::ClientError(Box::new(e)),
435+
Error::RpcError(e) => SubxtRpcError::ClientError(Box::new(e)),
436+
})
431437
}
432438
.boxed()
433439
}
@@ -449,7 +455,11 @@ impl RpcClientT for RpcClient {
449455
SubscriptionId::Str(s) => s.to_string(),
450456
};
451457
let stream = sub
452-
.map_err(|e| SubxtRpcError::DisconnectedWillReconnect(e.to_string()))
458+
// NOTE: The stream emits only one error `DisconnectWillReconnect if the connection was lost
459+
// and safe to wrap it in a `SubxtRpcError::DisconnectWillReconnect` here
460+
.map_err(|e: DisconnectedWillReconnect| {
461+
SubxtRpcError::DisconnectedWillReconnect(e.to_string())
462+
})
453463
.boxed();
454464

455465
Ok(RawRpcSubscription {

0 commit comments

Comments
 (0)