Skip to content

Commit

Permalink
feat(transports): add retries to HTTP transport
Browse files Browse the repository at this point in the history
  • Loading branch information
iskorotkov committed Dec 30, 2023
1 parent 6fcad83 commit 975f577
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 54 deletions.
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0.39"
tiny-keccak = { version = "2.0.1", features = ["keccak"] }
pin-project = "1.0"
async-recursion = "1.0.5"
chrono = "0.4.31"
# Optional deps
secp256k1 = { version = "0.28", features = ["recovery"], optional = true }
once_cell = { version = "1.8.0", optional = true }
Expand Down Expand Up @@ -73,7 +75,15 @@ tokio-stream = { version = "0.1", features = ["net"] }

[features]
default = ["http-tls", "signing", "ws-tls-tokio", "ipc-tokio"]
wasm = ["futures-timer/wasm-bindgen", "getrandom", "js-sys", "rand", "serde-wasm-bindgen", "wasm-bindgen", "wasm-bindgen-futures"]
wasm = [
"futures-timer/wasm-bindgen",
"getrandom",
"js-sys",
"rand",
"serde-wasm-bindgen",
"wasm-bindgen",
"wasm-bindgen-futures",
]
eip-1193 = ["wasm"]
_http_base = ["reqwest", "bytes", "url", "base64"]
http = ["_http_base"]
Expand Down
14 changes: 14 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ pub enum TransportError {
/// Arbitrary, developer-readable description of the occurred error.
#[display(fmt = "{}", _0)]
Message(String),
/// Recoverable rate limit error.
#[display(fmt = "rate limit: {}", _0)]
RateLimit(RateLimit),
}

/// Recoverable rate limit error.
#[derive(Display, Debug, Clone, PartialEq)]
pub enum RateLimit {
/// Retry-After: <http-date>
#[display(fmt = "retry after date {}", _0)]
Date(String),
/// Retry-After: <delay-seconds>
#[display(fmt = "retry after number of seconds {}", _0)]
Seconds(u64),
}

/// Errors which can occur when attempting to generate resource uri.
Expand Down
Loading

0 comments on commit 975f577

Please sign in to comment.