1use std::time::Duration;
4
5#[derive(Debug, thiserror::Error)]
7pub enum CopilotError {
8 #[error("HTTP error: {0}")]
10 Http(#[from] zenwave::Error),
11
12 #[error("Body error: {0}")]
14 Body(#[from] zenwave::BodyError),
15
16 #[error("SSE error: {0}")]
18 Stream(#[from] zenwave::sse::ParseError),
19
20 #[error("JSON error: {0}")]
22 Json(#[from] serde_json::Error),
23
24 #[error("{0}")]
26 Api(String),
27
28 #[error("Authorization pending")]
30 AuthorizationPending,
31
32 #[error("Device code expired")]
34 DeviceCodeExpired,
35
36 #[error("Access denied")]
38 AccessDenied,
39
40 #[error("Rate limit exceeded: {message}{}", retry_after.map(|d| format!(" (retry after {}s)", d.as_secs())).unwrap_or_default())]
42 RateLimit {
43 message: String,
45 retry_after: Option<Duration>,
47 },
48
49 #[error("Server error {status}: {message}")]
51 ServerError {
52 status: u16,
54 message: String,
56 },
57
58 #[error("Request timed out")]
60 Timeout,
61}
62
63impl CopilotError {
64 #[must_use]
69 pub fn status(&self) -> Option<u16> {
70 match self {
71 Self::Http(zenwave::Error::Http { status, .. }) => Some(status.as_u16()),
72 Self::ServerError { status, .. } => Some(*status),
73 _ => None,
74 }
75 }
76}