#[non_exhaustive]pub enum Error {
Api {
status: u16,
message: String,
},
RateLimited {
message: String,
retry_after: Option<Duration>,
},
Transport(Error),
Decode {
message: String,
body: String,
},
InvalidBaseUrl {
url: String,
message: String,
},
InvalidArgument {
message: String,
},
ContractRevert {
kind: RevertKind,
message: String,
error_name: Option<String>,
selector: Option<String>,
data: String,
retryable: bool,
token_address: Option<String>,
},
Rpc {
method: String,
message: String,
code: Option<i64>,
data: Option<Value>,
},
RpcTransport {
method: String,
source: Error,
},
}Expand description
Anything that can go wrong talking to the Fyuz API.
The two variants worth matching on explicitly are Error::RateLimited —
raised only after the client has exhausted its automatic retries — and
Error::Api, which carries the HTTP status and the server’s own message
parsed out of the {"error": "..."} envelope.
use fyuz::Error;
fn describe(err: &Error) -> String {
match err {
Error::RateLimited { retry_after, .. } => {
format!("slow down, retry after {:?}", retry_after)
}
Error::Api { status: 404, .. } => "no such token".to_string(),
other => other.to_string(),
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Api
The API answered with a non-2xx status other than 429.
message is the server’s {"error": "..."} text when the body carried
one, otherwise a trimmed excerpt of the raw body.
RateLimited
The API rate limit (120 requests/minute per IP) was hit and the configured number of retries did not clear it.
Fields
Transport(Error)
The request never produced an HTTP response: DNS failure, connection refused, TLS failure or the configured timeout elapsing.
Decode
A 2xx response arrived but did not deserialise into the expected type.
Fields
InvalidBaseUrl
FyuzClientBuilder::base_url was
given something that is not a usable HTTP base URL.
InvalidArgument
An argument failed validation before any request was sent.
Raised by the trading layer for a malformed address, an amount that is not a whole number of wei, or a build called without slippage protection.
ContractRevert
The contract rejected a call.
Raised from a simulated eth_call, so it costs nothing — this is the
failure you want, rather than paying gas to discover the same thing
on-chain. Error::is_graduated picks out the case where the token has
left the bonding curve.
Fields
kind: RevertKindClassification from shared/test-vectors/trade-errors.json.
Rpc
A JSON-RPC node returned an error, or something that was not a JSON-RPC response.
Fields
data: Option<Value>The node’s error.data, kept structurally rather than folded into
message.
This is where the revert payload lives on most providers, and it is the only place it can be read unambiguously: a node is free to put an address in its prose, and an address is longer than a 4-byte selector, so recovering the selector by scanning text is a guess.
RpcTransport
A JSON-RPC request never produced a response.
Distinct from Error::Transport so the failing method is visible: a
caller reading http transport error: … cannot tell an unreachable node
from an unreachable API. The underlying reqwest::Error is kept, so
Error::is_timeout still answers correctly.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_rate_limited(&self) -> bool
pub fn is_rate_limited(&self) -> bool
true for Error::RateLimited.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
true when the API answered 404 — an unknown token, profile or round.
Sourcepub fn is_graduated(&self) -> bool
pub fn is_graduated(&self) -> bool
true when a trade was refused because the token left the bonding curve.
The curve is closed once a token graduates, and every swap entrypoint reverts. Trade its DEX pair instead.
Sourcepub fn is_retryable_revert(&self) -> bool
pub fn is_retryable_revert(&self) -> bool
true when the contract rejected the call and retrying could plausibly
help — a slippage miss or an expired deadline, not a closed curve.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
true when the request timed out rather than being answered.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
The server’s Retry-After, when it sent one with a 429.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()