Skip to main content

dioxus_ai/
error.rs

1//! Error types for dioxus-ai
2
3use thiserror::Error;
4
5/// Errors that can occur in dioxus-ai
6#[derive(Debug, Error, Clone)]
7pub enum DioxusAiError {
8    /// HTTP request failed
9    #[error("Request failed: {0}")]
10    RequestFailed(String),
11
12    /// Invalid provider
13    #[error("Invalid provider: {0}")]
14    InvalidProvider(String),
15
16    /// API error response
17    #[error("API error: {0}")]
18    ApiError(String),
19
20    /// Parse error
21    #[error("Parse error: {0}")]
22    ParseError(String),
23
24    /// Stream error
25    #[error("Stream error: {0}")]
26    StreamError(String),
27
28    /// Missing configuration
29    #[error("Missing configuration: {0}")]
30    MissingConfig(String),
31}
32
33impl From<serde_json::Error> for DioxusAiError {
34    fn from(e: serde_json::Error) -> Self {
35        DioxusAiError::ParseError(e.to_string())
36    }
37}
38
39impl From<cortexai_llm_client::LlmClientError> for DioxusAiError {
40    fn from(e: cortexai_llm_client::LlmClientError) -> Self {
41        DioxusAiError::ApiError(e.to_string())
42    }
43}
44
45pub type Result<T> = std::result::Result<T, DioxusAiError>;