use sova_core::{IntoResponse, Response};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AiError {
#[error("ai: no model configured (use Ai::model(...) or Ai::fake(...))")]
NoModel,
#[error("ai: prompt or messages required")]
EmptyPrompt,
#[error(transparent)]
Sdk(#[from] aisdk::Error),
}
impl IntoResponse for AiError {
fn into_response(self) -> Response {
let status = match &self {
AiError::NoModel | AiError::EmptyPrompt => 500,
AiError::Sdk(_) => 502,
};
Response::text(self.to_string()).status(status)
}
}
impl From<AiError> for sova_core::Error {
fn from(value: AiError) -> Self {
sova_core::Error::Internal(value.to_string())
}
}