hookburn-core 0.2.2

Shared HTTP client and WebhookSender trait for the Hookburn crates
Documentation
// crates/hookburn-core/src/error.rs
use std::fmt;
use thiserror::Error;

/// Helper for formatting optional status codes in error messages
struct StatusCodeDisplay(Option<u16>);

impl fmt::Display for StatusCodeDisplay {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self.0 {
            Some(code) => write!(f, "{code}"),
            None => write!(f, "unknown"),
        }
    }
}

/// Most common error types
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum CoreError {
    /// An HTTP or network-level failure from the underlying reqwest client.
    #[error("network error: {0}")]
    Network(#[from] reqwest::Error),

    /// JSON serialization or deserialization failed.
    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    /// Service not found in registry.
    #[error("service not found: {0}")]
    ServiceNotFound(String),

    /// Service creation failed.
    #[error("service creation failed: {0}")]
    ServiceCreationFailed(String),

    /// Service returned an error.
    #[error("service error: {0}")]
    ServiceError(String),

    /// Invalid service configuration.
    #[error("invalid service configuration: {0}")]
    InvalidServiceConfig(String),

    /// Message conversion failed.
    #[error("message conversion failed: {0}")]
    MessageConversionFailed(String),

    /// Rate limit exceeded.
    #[error("rate limit exceeded, retry after {retry_after:?}")]
    RateLimitExceeded {
        /// Length of time to retry connection
        retry_after: std::time::Duration,
    },

    /// Service returned an error with status code.
    #[error("service {service} returned error {}: {message}", StatusCodeDisplay(*status_code))]
    ServiceReturnedError {
        /// Services
        service: String,
        /// Code
        status_code: Option<u16>,
        /// Message
        message: String,
    },

    /// All retry attempts failed.
    #[error("all retry attempts failed: {0}")]
    RetryExhausted(String),
}