steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
use std::fmt;

/// Errors returned by [`GasSteamUser`](super::GasSteamUser).
#[derive(Debug)]
pub enum GasError {
    /// HTTP / network error from reqwest.
    Http(reqwest::Error),
    /// The GAS endpoint returned an error message. `status` is the HTTP status
    /// observed when the error was constructed (preserved so callers can
    /// distinguish transport vs. application-level failures).
    Api { status: u16, message: String },
    /// JSON serialization / deserialization error.
    Json(serde_json::Error),
    /// The GAS endpoint returned success but no data.
    NoData,
    /// All retry attempts exhausted without a successful response.
    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)
    }
}