sentd 1.0.0

Official Rust SDK for the SENTD Email API
Documentation
use thiserror::Error;

/// Error types for the SENTD SDK
#[derive(Error, Debug)]
pub enum Error {
    #[error("Authentication error: {0}")]
    Authentication(String),

    #[error("Not found: {0}")]
    NotFound(String),

    #[error("Rate limit exceeded: {0}")]
    RateLimit(String),

    #[error("Validation error: {0}")]
    Validation(String),

    #[error("API error (status {status}): {message}")]
    Api { status: u16, message: String },

    #[error("Network error: {0}")]
    Network(#[from] reqwest::Error),

    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),
}

impl Error {
    pub fn from_status(status: u16, message: String) -> Self {
        match status {
            401 => Error::Authentication(message),
            404 => Error::NotFound(message),
            429 => Error::RateLimit(message),
            400 | 422 => Error::Validation(message),
            _ => Error::Api { status, message },
        }
    }
}