Skip to main content

aither_copilot/
error.rs

1//! Error types for GitHub Copilot API integration.
2
3use std::time::Duration;
4
5/// Errors that can arise when calling the GitHub Copilot API.
6#[derive(Debug, thiserror::Error)]
7pub enum CopilotError {
8    /// HTTP layer errors from zenwave.
9    #[error("HTTP error: {0}")]
10    Http(#[from] zenwave::Error),
11
12    /// Response body parsing failures.
13    #[error("Body error: {0}")]
14    Body(#[from] zenwave::BodyError),
15
16    /// SSE parsing failures.
17    #[error("SSE error: {0}")]
18    Stream(#[from] zenwave::sse::ParseError),
19
20    /// JSON serialization/deserialization errors.
21    #[error("JSON error: {0}")]
22    Json(#[from] serde_json::Error),
23
24    /// API contract violations or unsupported operations.
25    #[error("{0}")]
26    Api(String),
27
28    /// OAuth authorization pending (user hasn't completed flow yet).
29    #[error("Authorization pending")]
30    AuthorizationPending,
31
32    /// OAuth device code expired.
33    #[error("Device code expired")]
34    DeviceCodeExpired,
35
36    /// OAuth access denied by user.
37    #[error("Access denied")]
38    AccessDenied,
39
40    /// Rate limit exceeded (HTTP 429).
41    #[error("Rate limit exceeded: {message}{}", retry_after.map(|d| format!(" (retry after {}s)", d.as_secs())).unwrap_or_default())]
42    RateLimit {
43        /// Message from the API.
44        message: String,
45        /// Suggested retry delay from Retry-After header.
46        retry_after: Option<Duration>,
47    },
48
49    /// Server error (HTTP 5xx).
50    #[error("Server error {status}: {message}")]
51    ServerError {
52        /// HTTP status code.
53        status: u16,
54        /// Error message.
55        message: String,
56    },
57
58    /// Request timed out.
59    #[error("Request timed out")]
60    Timeout,
61}