lib_client_anthropic/
error.rs

1//! Error types for the Anthropic client.
2
3use thiserror::Error;
4
5/// Anthropic API error type.
6#[derive(Debug, Error)]
7pub enum AnthropicError {
8    /// HTTP request failed.
9    #[error("Request failed: {0}")]
10    Request(#[from] reqwest::Error),
11
12    /// API returned an error response.
13    #[error("API error ({status}): {message}")]
14    Api { status: u16, message: String },
15
16    /// Rate limited by the API.
17    #[error("Rate limited, retry after {retry_after}s")]
18    RateLimited { retry_after: u64 },
19
20    /// Authentication failed.
21    #[error("Unauthorized: invalid API key")]
22    Unauthorized,
23
24    /// Request was forbidden.
25    #[error("Forbidden: {0}")]
26    Forbidden(String),
27
28    /// Resource not found.
29    #[error("Not found: {0}")]
30    NotFound(String),
31
32    /// JSON serialization/deserialization error.
33    #[error("JSON error: {0}")]
34    Json(#[from] serde_json::Error),
35
36    /// Invalid request parameters.
37    #[error("Invalid request: {0}")]
38    InvalidRequest(String),
39
40    /// Server overloaded.
41    #[error("Server overloaded, retry later")]
42    Overloaded,
43}
44
45/// Result type alias for Anthropic operations.
46pub type Result<T> = std::result::Result<T, AnthropicError>;