qstash-rs 0.6.0

A Rust SDK for Upstash QStash
Documentation
use reqwest::StatusCode;
use thiserror::Error;

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

/// Errors returned by the QStash client and receiver.
#[derive(Debug, Error)]
pub enum Error {
    /// The client or request was configured with invalid input.
    #[error("invalid configuration: {message}")]
    Config {
        /// Human-readable validation detail.
        message: String,
    },

    /// The caller built an invalid request.
    #[error("invalid request: {message}")]
    InvalidRequest {
        /// Human-readable validation detail.
        message: String,
    },

    /// The underlying HTTP transport failed.
    #[error("transport error: {0}")]
    Transport(#[source] reqwest::Error),

    /// JSON serialization failed before the request was sent.
    #[error("failed to serialize request body: {0}")]
    Serialize(#[source] serde_json::Error),

    /// The QStash API returned a non-success status code.
    #[error("qstash api error ({status}): {message}")]
    Api {
        /// HTTP status returned by QStash.
        status: StatusCode,
        /// Best-effort error message extracted from the response payload.
        message: String,
        /// Raw response body when one was returned.
        body: Option<String>,
    },

    /// A success response could not be decoded into the expected model.
    #[error("failed to decode response body with status {status}: {source}")]
    Decode {
        /// HTTP status returned by QStash.
        status: StatusCode,
        /// Raw response body.
        body: String,
        /// JSON decoding error.
        #[source]
        source: serde_json::Error,
    },

    /// JWT verification failed while validating an inbound QStash request.
    #[error("jwt verification failed: {0}")]
    Jwt(#[from] jsonwebtoken::errors::Error),

    /// A verified JWT did not match the expected body or subject.
    #[error("signature verification failed: {message}")]
    Signature {
        /// Human-readable verification detail.
        message: String,
    },
}