Skip to main content

llmrix_rust_sdk/
error.rs

1use thiserror::Error;
2
3/// All errors returned by the Llmrix SDK.
4#[derive(Debug, Error)]
5pub enum LlmrixError {
6    /// Low-level HTTP / connection failure.
7    #[error("HTTP transport error: {0}")]
8    Transport(#[from] reqwest::Error),
9
10    /// JSON serialization or deserialization failure.
11    #[error("JSON error: {0}")]
12    Json(#[from] serde_json::Error),
13
14    /// The server returned a 4xx or 5xx status.
15    /// Inspect `status` to branch on specific codes (e.g. 404, 429).
16    #[error("API error {status}: {message}")]
17    Api {
18        status: u16,
19        message: String,
20        body: String,
21    },
22
23    /// Returned on HTTP 401 (invalid API key) or 503
24    /// (server running in native mode without auth configured).
25    #[error("Authentication error {status}: {message}")]
26    Auth { status: u16, message: String },
27
28    /// Returned when the SSE stream cannot be read or parsed.
29    #[error("SSE stream error: {0}")]
30    Stream(String),
31
32    /// General SDK-level error.
33    #[error("{0}")]
34    Other(String),
35}
36
37pub type Result<T> = std::result::Result<T, LlmrixError>;