1use sova_core::{IntoResponse, Response};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum AiError {
9 #[error("ai: no model configured (use Ai::model(...) or Ai::fake(...))")]
11 NoModel,
12 #[error("ai: prompt or messages required")]
14 EmptyPrompt,
15 #[error(transparent)]
17 Sdk(#[from] aisdk::Error),
18}
19
20impl IntoResponse for AiError {
21 fn into_response(self) -> Response {
22 let status = match &self {
23 AiError::NoModel | AiError::EmptyPrompt => 500,
24 AiError::Sdk(_) => 502,
25 };
26 Response::text(self.to_string()).status(status)
27 }
28}
29
30impl From<AiError> for sova_core::Error {
31 fn from(value: AiError) -> Self {
32 sova_core::Error::Internal(value.to_string())
33 }
34}