hypixel-sdk 0.2.1

Async client for the Hypixel Public API with typed models and SkyBlock helpers
Documentation
use std::time::Duration;

/// Errors returned by the Hypixel SDK.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// A method requiring authentication was called without an API key configured.
    #[error("an API key is required for this endpoint but none was configured")]
    MissingApiKey,

    /// The configured API key was rejected by the API (HTTP 403).
    #[error("the API key was rejected (403 Forbidden)")]
    InvalidApiKey,

    /// The request was rate limited (HTTP 429).
    #[error("rate limited; retry after {}s", retry_after.map(|d| d.as_secs()).unwrap_or(0))]
    RateLimited {
        /// Suggested wait duration parsed from the `Retry-After` header, if present.
        retry_after: Option<Duration>,
    },

    /// The API responded with a non-success status and an error cause.
    #[error("API error ({status}): {cause}")]
    Api {
        /// HTTP status code returned by the API.
        status: u16,
        /// The `cause` field from the API response body, if available.
        cause: String,
    },

    /// The request could not be sent or the connection failed.
    #[error("HTTP transport error: {0}")]
    Http(#[from] reqwest::Error),

    /// The response body could not be deserialized into the expected type.
    #[error("failed to decode response: {0}")]
    Decode(#[from] serde_json::Error),
}

/// Convenience alias for results returned by this crate.
pub type Result<T> = std::result::Result<T, Error>;