reddit-insights 1.0.0

Official Rust SDK for the Reddit Insights API
Documentation
//! Error types for the Reddit Insights SDK

use std::fmt;

/// Result type for Reddit Insights SDK operations
pub type Result<T> = std::result::Result<T, Error>;

/// Error type for Reddit Insights SDK
#[derive(Debug)]
pub enum Error {
    /// Authentication failed (401)
    Authentication(String),
    /// Rate limit exceeded (429)
    RateLimit(String),
    /// Request validation failed (400)
    Validation(String),
    /// API error with status code
    Api { status_code: u16, message: String },
    /// HTTP request failed
    Request(String),
    /// JSON parsing failed
    Parse(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Authentication(msg) => write!(f, "Authentication error: {}", msg),
            Error::RateLimit(msg) => write!(f, "Rate limit exceeded: {}", msg),
            Error::Validation(msg) => write!(f, "Validation error: {}", msg),
            Error::Api { status_code, message } => {
                write!(f, "API error (status {}): {}", status_code, message)
            }
            Error::Request(msg) => write!(f, "Request failed: {}", msg),
            Error::Parse(msg) => write!(f, "Parse error: {}", msg),
        }
    }
}

impl std::error::Error for Error {}

impl From<reqwest::Error> for Error {
    fn from(err: reqwest::Error) -> Self {
        Error::Request(err.to_string())
    }
}

impl From<serde_json::Error> for Error {
    fn from(err: serde_json::Error) -> Self {
        Error::Parse(err.to_string())
    }
}