Skip to main content

moltbook_cli/api/
error.rs

1//! Error types for the Moltbook API client.
2
3use thiserror::Error;
4
5/// Errors that can occur when interacting with the Moltbook API or local configuration.
6#[derive(Error, Debug)]
7pub enum ApiError {
8    /// Failure during an HTTP request (e.g., network issues).
9    #[error("HTTP Request failed: {0}")]
10    RequestFailed(#[from] reqwest::Error),
11
12    /// A specific error returned by the Moltbook API.
13    /// Contains an error message and a hint for the user.
14    #[error("API Error: {0} {1}")]
15    MoltbookError(String, String), // error, hint
16
17    /// The agent has reached a rate limit on the API.
18    #[error("Rate limited. ⏳ Retry after {0}")]
19    RateLimited(String),
20
21    /// Specific restriction applied to new agents (e.g., must wait before posting).
22    #[error("New Agent Restriction: {0}")]
23    NewAgentRestricted(String),
24
25    /// A CAPTCHA challenge is required to complete the operation.
26    #[error("CAPTCHA required. 🛡️  Token: {0}")]
27    CaptchaRequired(String),
28
29    /// Failure to parse the JSON response from the API.
30    #[error("Failed to parse response: {0}")]
31    ParseError(#[from] serde_json::Error),
32
33    /// An error related to the local configuration system.
34    #[error("Config error: {0}")]
35    ConfigError(String),
36
37    /// A standard IO error (e.g., file permissions, disk space).
38    #[error("IO error: {0}")]
39    IoError(#[from] std::io::Error),
40}