titanium_http/
error.rs

1//! HTTP error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during HTTP operations.
6#[derive(Debug, Error)]
7pub enum HttpError {
8    /// Request failed.
9    #[error("Request error: {0}")]
10    Request(#[from] reqwest::Error),
11
12    /// JSON serialization/deserialization error.
13    #[error("JSON error: {0}")]
14    Json(#[from] serde_json::Error),
15
16    /// Rate limited by Discord.
17    #[error("Rate limited, retry after {retry_after_ms}ms")]
18    RateLimited {
19        /// Milliseconds until rate limit expires.
20        retry_after_ms: u64,
21        /// Whether this is a global rate limit.
22        global: bool,
23    },
24
25    /// Discord API returned an error.
26    #[error("Discord API error {code}: {message}")]
27    Discord {
28        /// Error code.
29        code: u32,
30        /// Error message.
31        message: String,
32    },
33
34    /// Unauthorized (invalid token).
35    #[error("Unauthorized: Invalid token")]
36    Unauthorized,
37
38    /// Forbidden (missing permissions).
39    #[error("Forbidden: Missing permissions")]
40    Forbidden,
41
42    /// Resource not found.
43    #[error("Not found")]
44    NotFound,
45
46    /// Server error.
47    #[error("Discord server error: {0}")]
48    ServerError(u16),
49}
50
51/// Discord API error response.
52#[derive(Debug, serde::Deserialize)]
53pub struct DiscordError {
54    pub code: u32,
55    pub message: String,
56    #[serde(default)]
57    #[allow(dead_code)]
58    pub errors: Option<serde_json::Value>,
59}