use std::fmt;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("transport failure reaching the AI endpoint: {0}")]
Transport(String),
#[error("AI endpoint responded with status {code}: {body}")]
Status {
code: u16,
body: String,
},
#[error("response was truncated (finish_reason=length) after all retries")]
Truncated,
#[error("response did not match the expected schema: {0}")]
MalformedResponse(String),
#[error("all {attempts} attempt(s) failed; last error: {last_error}")]
RetriesExhausted {
attempts: u32,
last_error: Box<Error>,
},
}
impl Error {
pub(crate) fn transport(err: impl fmt::Display) -> Self {
Self::Transport(err.to_string())
}
}