1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum ProviderError {
9 #[error("HTTP {status}: {body}")]
11 Http {
12 status: u16,
14 body: String,
16 retry_after: Option<u64>,
18 },
19
20 #[error("Request failed: {0}")]
22 Request(#[from] reqwest::Error),
23
24 #[error("Response parse error: {0}")]
26 Parse(String),
27
28 #[error("API key not configured for provider '{0}'")]
30 MissingApiKey(String),
31
32 #[error("Provider error: {0}")]
34 Other(String),
35}
36
37impl ProviderError {
38 pub fn http_status(&self) -> Option<u16> {
40 match self {
41 ProviderError::Http { status, .. } => Some(*status),
42 _ => None,
43 }
44 }
45
46 pub fn retry_after_seconds(&self) -> Option<u64> {
48 match self {
49 ProviderError::Http { retry_after, .. } => *retry_after,
50 _ => None,
51 }
52 }
53
54 pub fn is_rate_limited(&self) -> bool {
56 matches!(self, ProviderError::Http { status: 429, .. })
57 }
58}
59
60#[derive(Debug, Error)]
62#[error("All providers in cascade '{cascade_name}' failed: {message}\nFailed prompt persisted to: {}", .failed_prompt_path.display())]
63pub struct CascadeError {
64 pub cascade_name: String,
66 pub message: String,
68 pub failed_prompt_path: PathBuf,
70}