Skip to main content

pi_ai/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum Error {
5    #[error("missing API key for provider {0}")]
6    MissingApiKey(String),
7
8    #[error("unsupported provider/api: {0}")]
9    UnsupportedProvider(String),
10
11    #[error("http error: {0}")]
12    Http(#[from] reqwest::Error),
13
14    #[error("invalid response from provider: {0}")]
15    InvalidResponse(String),
16
17    #[error("provider returned an error (status {status}): {body}")]
18    ProviderError { status: u16, body: String },
19
20    #[error("request cancelled")]
21    Cancelled,
22
23    #[error("retried {attempts} times, last error: {source}")]
24    RetryExhausted { attempts: u32, source: Box<Error> },
25
26    #[error("json: {0}")]
27    Json(#[from] serde_json::Error),
28
29    #[error("io: {0}")]
30    Io(#[from] std::io::Error),
31
32    #[error("{0}")]
33    Other(String),
34}
35
36pub type Result<T> = std::result::Result<T, Error>;