archivist-core 0.2.0

Platform-neutral core for the FicHub companion bot: FicHub REST API client, search/recommendation/download command logic, intent classification, pagination cache, and the PlatformMessage IR. Shared by every platform adapter (Discord, Telegram, Matrix, Slack, IRC, fediverse, CLI, web).
Documentation
//! Error types for the bot.

use thiserror::Error;

/// Bot-wide error type. Every variant is platform-neutral.
#[derive(Debug, Error)]
pub enum BotError {
    /// Outgoing HTTP request failed.
    #[error("HTTP request failed: {0}")]
    Http(#[from] reqwest::Error),
    /// The API returned an explicit error code + message.
    #[error("API returned error {err}: {msg}")]
    Api {
        /// FicHub API error code.
        err: i32,
        /// Human-readable error message.
        msg: String,
    },
    /// The API returned a non-200 status with a raw body.
    #[error("API returned non-200 status {status}: {body}")]
    Status {
        /// HTTP status code.
        status: u16,
        /// Raw response body.
        body: String,
    },
    /// JSON deserialization failed.
    #[error("JSON parse failed: {0}")]
    Json(#[from] serde_json::Error),
    /// Redis operation failed.
    #[error("Redis error: {0}")]
    Redis(#[from] redis::RedisError),
    /// The user has no linked FicHub account.
    #[error("Not linked: run /link to connect your FicHub account")]
    NotLinked,
    /// Bad or missing configuration.
    #[error("Configuration error: {0}")]
    Config(String),
    /// Invalid command usage.
    #[error("Command error: {0}")]
    Command(String),
    /// Rate limited by a shared Redis bucket.
    #[error("Rate limited — retry in {retry_after_secs}s")]
    RateLimited {
        /// Seconds to wait before retrying.
        retry_after_secs: u64,
    },
    /// Anything else.
    #[error("Internal error: {0}")]
    Other(String),
}

/// Convenience alias.
pub type Result<T> = std::result::Result<T, BotError>;