use anyllm_translate::TranslateError;
#[derive(Debug, thiserror::Error)]
pub enum ClientError {
#[error("translation error: {0}")]
Translation(#[from] TranslateError),
#[error("request failed: {0}")]
Transport(#[from] reqwest::Error),
#[error("API error ({status}): {message}")]
ApiError {
status: u16,
message: String,
body: String,
},
#[error("response deserialization failed: {0}")]
Deserialization(String),
#[error("SSE stream error: {0}")]
Sse(#[from] crate::sse::SseError),
}
impl ClientError {
pub fn status_code(&self) -> u16 {
match self {
Self::ApiError { status, .. } => *status,
_ => 500,
}
}
}