async_anthropic/
errors.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum CreateMessagesError {
5    #[error(transparent)]
6    AnthropicError(#[from] AnthropicError),
7}
8
9#[derive(Debug, Error)]
10pub enum AnthropicError {
11    #[error("network error: {0}")]
12    NetworkError(#[from] reqwest::Error),
13
14    #[error("malformed request: {0}")]
15    BadRequest(String),
16
17    #[error("api error: {0}")]
18    ApiError(String),
19
20    #[error("unauthorized; check your API key")]
21    Unauthorized,
22
23    #[error("unknown error: {0}")]
24    Unknown(String),
25
26    #[error("unexpected error occurred")]
27    UnexpectedError,
28}
29
30impl From<backoff::Error<AnthropicError>> for AnthropicError {
31    fn from(err: backoff::Error<AnthropicError>) -> Self {
32        match err {
33            backoff::Error::Permanent(err) => err,
34            backoff::Error::Transient { .. } => AnthropicError::UnexpectedError,
35        }
36    }
37}