mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 20:21:03 +00:00
Unify error enums in substrate and ethereum clients with thiserror (#1094)
* Unify error enums in substrate and ethereum clients with `thiserror` Related to https://github.com/paritytech/parity-bridges-common/issues/857 * Add license pre-amble * rustfmt * Fix spelling
This commit is contained in:
committed by
Bastian Köcher
parent
7b4f1c2236
commit
5842968273
@@ -16,11 +16,13 @@
|
||||
|
||||
//! Utilities used by different relays.
|
||||
|
||||
pub use error::Error;
|
||||
pub use relay_loop::{relay_loop, relay_metrics};
|
||||
|
||||
use backoff::{backoff::Backoff, ExponentialBackoff};
|
||||
use futures::future::FutureExt;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Max delay after connection-unrelated error happened before we'll try the
|
||||
/// same request again.
|
||||
@@ -29,6 +31,7 @@ pub const MAX_BACKOFF_INTERVAL: Duration = Duration::from_secs(60);
|
||||
/// reconnection again.
|
||||
pub const CONNECTION_ERROR_DELAY: Duration = Duration::from_secs(10);
|
||||
|
||||
pub mod error;
|
||||
pub mod initialize;
|
||||
pub mod metrics;
|
||||
pub mod relay_loop;
|
||||
@@ -111,11 +114,13 @@ pub trait MaybeConnectionError {
|
||||
}
|
||||
|
||||
/// Stringified error that may be either connection-related or not.
|
||||
#[derive(Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum StringifiedMaybeConnectionError {
|
||||
/// The error is connection-related error.
|
||||
#[error("{0}")]
|
||||
Connection(String),
|
||||
/// The error is connection-unrelated error.
|
||||
#[error("{0}")]
|
||||
NonConnection(String),
|
||||
}
|
||||
|
||||
@@ -139,15 +144,6 @@ impl MaybeConnectionError for StringifiedMaybeConnectionError {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for StringifiedMaybeConnectionError {
|
||||
fn to_string(&self) -> String {
|
||||
match *self {
|
||||
StringifiedMaybeConnectionError::Connection(ref err) => err.clone(),
|
||||
StringifiedMaybeConnectionError::NonConnection(ref err) => err.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Exponential backoff for connection-unrelated errors retries.
|
||||
pub fn retry_backoff() -> ExponentialBackoff {
|
||||
ExponentialBackoff {
|
||||
|
||||
Reference in New Issue
Block a user