open-library-api-rs 0.1.0

Async Rust client for the Open Library API
Documentation
// v0.0.1
use thiserror::Error;

/// All errors that can be returned by this library.
#[derive(Debug, Error)]
pub enum Error {
    /// Input validation failed before any network call was made.
    #[error("invalid input: {0}")]
    InvalidInput(String),

    /// A network or transport-level error from reqwest.
    #[error("HTTP error: {0}")]
    Http(#[from] reqwest::Error),

    /// The server returned a non-2xx status code.
    #[error("server returned {code} for {url}")]
    Status { code: u16, url: String },

    /// The server returned 404 Not Found.
    #[error("not found: {0}")]
    NotFound(String),

    /// The server returned 429 Too Many Requests, or the local rate limiter
    /// rejected the call.
    #[error("rate limited")]
    RateLimited,

    /// The response body could not be parsed as the expected JSON type.
    #[error("deserialize error: {source} — body: {body}")]
    Deserialize {
        source: serde_json::Error,
        body: String,
    },

    /// The response body exceeded the 10 MB safety cap.
    #[error("response body exceeded the 10 MB size limit")]
    ResponseTooLarge,

    /// The connection or read timeout was exceeded.
    #[error("request timed out")]
    Timeout,

    /// URL construction failed (should not happen with valid inputs).
    #[error("URL error: {0}")]
    Url(#[from] url::ParseError),
}

/// Convenience alias used throughout the library.
pub type Result<T> = std::result::Result<T, Error>;