steam-user 0.1.0

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

/// Errors returned by [`RemoteSteamUser`](crate::RemoteSteamUser).
#[derive(Debug)]
pub enum RemoteSteamUserError {
    /// HTTP / network error from reqwest.
    Http(reqwest::Error),
    /// The remote API returned an error message. `status` is the HTTP status
    /// observed when the error was constructed (preserved so callers can
    /// distinguish 4xx from 5xx without re-parsing `message`).
    Api { status: u16, message: String },
    /// JSON serialization / deserialization error.
    Json(serde_json::Error),
    /// All retry attempts exhausted without a successful response.
    AllRetriesFailed,
    /// No server URLs were provided.
    NoUrls,
}

impl fmt::Display for RemoteSteamUserError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Http(e) => write!(f, "HTTP error: {}", e),
            Self::Api { status, message } => write!(f, "API error (HTTP {}): {}", status, message),
            Self::Json(e) => write!(f, "JSON error: {}", e),
            Self::AllRetriesFailed => write!(f, "All retry attempts failed"),
            Self::NoUrls => write!(f, "No server URLs provided"),
        }
    }
}

impl std::error::Error for RemoteSteamUserError {
    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 RemoteSteamUserError {
    fn from(e: reqwest::Error) -> Self {
        Self::Http(e)
    }
}

impl From<serde_json::Error> for RemoteSteamUserError {
    fn from(e: serde_json::Error) -> Self {
        Self::Json(e)
    }
}