use std::fmt;
#[derive(Debug)]
pub enum GasError {
Http(reqwest::Error),
Api { status: u16, message: String },
Json(serde_json::Error),
NoData,
AllRetriesFailed,
}
impl fmt::Display for GasError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Http(e) => write!(f, "GAS HTTP error: {}", e),
Self::Api { status, message } => write!(f, "GAS API error (HTTP {}): {}", status, message),
Self::Json(e) => write!(f, "GAS JSON error: {}", e),
Self::NoData => write!(f, "GAS returned success but no data"),
Self::AllRetriesFailed => write!(f, "GAS: all retry attempts failed"),
}
}
}
impl std::error::Error for GasError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Http(e) => Some(e),
Self::Json(e) => Some(e),
_ => None,
}
}
}
impl From<reqwest::Error> for GasError {
fn from(e: reqwest::Error) -> Self {
Self::Http(e)
}
}
impl From<serde_json::Error> for GasError {
fn from(e: serde_json::Error) -> Self {
Self::Json(e)
}
}