use std::time::Duration;
#[derive(Debug, thiserror::Error)]
pub enum CopilotError {
#[error("HTTP error: {0}")]
Http(#[from] zenwave::Error),
#[error("Body error: {0}")]
Body(#[from] zenwave::BodyError),
#[error("SSE error: {0}")]
Stream(#[from] zenwave::sse::ParseError),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("{0}")]
Api(String),
#[error("Authorization pending")]
AuthorizationPending,
#[error("Device code expired")]
DeviceCodeExpired,
#[error("Access denied")]
AccessDenied,
#[error("Rate limit exceeded: {message}{}", retry_after.map(|d| format!(" (retry after {}s)", d.as_secs())).unwrap_or_default())]
RateLimit {
message: String,
retry_after: Option<Duration>,
},
#[error("Server error {status}: {message}")]
ServerError {
status: u16,
message: String,
},
#[error("Request timed out")]
Timeout,
}
impl CopilotError {
#[must_use]
pub const fn status(&self) -> Option<u16> {
match self {
Self::Http(zenwave::Error::Http { status, .. }) => Some(status.as_u16()),
Self::ServerError { status, .. } => Some(*status),
_ => None,
}
}
}