Skip to main content

ollama_oxide/
error.rs

1//! Error types for ollama-oxide library
2//!
3//! This module defines the error types used throughout the library,
4//! including conversions from external error types and the Result type alias.
5
6use thiserror::Error;
7
8/// Error type for all ollama-oxide operations
9#[derive(Debug, Error)]
10pub enum Error {
11    #[error("HTTP request failed: {0}")]
12    HttpError(String),
13
14    #[error("HTTP status error: {0}")]
15    HttpStatusError(u16),
16
17    #[error("Serialization error: {0}")]
18    SerializationError(String),
19
20    #[error("API error: {message}")]
21    ApiError { message: String },
22
23    #[error("Connection error: {0}")]
24    ConnectionError(String),
25
26    #[error("Invalid URL: {0}")]
27    InvalidUrlError(#[from] url::ParseError),
28
29    #[error("Request timeout after {0} seconds")]
30    TimeoutError(u64),
31
32    #[error("Maximum retry attempts ({0}) exceeded")]
33    MaxRetriesExceededError(u32),
34
35    /// Error while reading or parsing a streaming (NDJSON) response.
36    #[error("Stream error: {0}")]
37    StreamError(String),
38}
39
40impl From<reqwest::Error> for Error {
41    fn from(err: reqwest::Error) -> Self {
42        Error::HttpError(err.to_string())
43    }
44}
45
46impl From<serde_json::Error> for Error {
47    fn from(err: serde_json::Error) -> Self {
48        Error::SerializationError(err.to_string())
49    }
50}
51
52/// Result type alias for ollama-oxide operations
53pub type Result<T> = std::result::Result<T, Error>;