Skip to content

Commit bff31d5

Browse files
committed
refactor(dapi-client): replace CanRetry.is_node_failure with !CanRetry.can_retry()
1 parent f984ced commit bff31d5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

packages/rs-dapi-client/src/dapi_client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ pub enum DapiClientError<TE: Mockable> {
3939
}
4040

4141
impl<TE: CanRetry + Mockable> CanRetry for DapiClientError<TE> {
42-
fn is_node_failure(&self) -> bool {
42+
fn can_retry(&self) -> bool {
4343
use DapiClientError::*;
4444
match self {
45-
NoAvailableAddresses => false,
46-
Transport(transport_error, _) => transport_error.is_node_failure(),
47-
AddressList(_) => false,
45+
NoAvailableAddresses => true,
46+
Transport(transport_error, _) => transport_error.can_retry(),
47+
AddressList(_) => true,
4848
#[cfg(feature = "mocks")]
4949
Mock(_) => false,
5050
}
@@ -222,7 +222,7 @@ impl DapiRequestExecutor for DapiClient {
222222
tracing::trace!(?response, "received {} response", response_name);
223223
}
224224
Err(error) => {
225-
if error.is_node_failure() {
225+
if !error.can_retry() {
226226
if applied_settings.ban_failed_address {
227227
let mut address_list = self
228228
.address_list
@@ -253,12 +253,12 @@ impl DapiRequestExecutor for DapiClient {
253253
duration.as_secs_f32()
254254
)
255255
})
256-
.when(|e| e.is_node_failure())
256+
.when(|e| !e.can_retry())
257257
.instrument(tracing::info_span!("request routine"))
258258
.await;
259259

260260
if let Err(error) = &result {
261-
if error.is_node_failure() {
261+
if !error.can_retry() {
262262
tracing::error!(?error, "request failed");
263263
}
264264
}

packages/rs-dapi-client/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ impl<T: transport::TransportRequest + Send> DapiRequest for T {
7373
/// Allows to flag the transport error variant how tolerant we are of it and whether we can
7474
/// try to do a request again.
7575
pub trait CanRetry {
76+
/// Returns true if the operation can be retried safely, false means it's unspecified
77+
fn can_retry(&self) -> bool;
78+
7679
/// Get boolean flag that indicates if the error is retryable.
77-
fn is_node_failure(&self) -> bool;
80+
///
81+
/// Depreacted in favor of [CanRetry::can_retry].
82+
#[deprecated = "Use !can_retry() instead"]
83+
fn is_node_failure(&self) -> bool {
84+
!self.can_retry()
85+
}
7886
}

packages/rs-dapi-client/src/transport/grpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ impl TransportClient for CoreGrpcClient {
7575
}
7676

7777
impl CanRetry for dapi_grpc::tonic::Status {
78-
fn is_node_failure(&self) -> bool {
78+
fn can_retry(&self) -> bool {
7979
let code = self.code();
8080

8181
use dapi_grpc::tonic::Code::*;
82-
matches!(
82+
!matches!(
8383
code,
8484
Ok | DataLoss
8585
| Cancelled

0 commit comments

Comments
 (0)