jules_rs/error.rs
1//! Error types for the Jules API client.
2//!
3//! This module provides a unified error type [`JulesError`] that covers all
4//! possible error conditions when interacting with the Jules API.
5
6use thiserror::Error;
7
8/// The error type for Jules API operations.
9///
10/// This enum represents all possible errors that can occur when using the
11/// [`JulesClient`](crate::JulesClient).
12#[derive(Debug, Error)]
13pub enum JulesError {
14 /// An HTTP request failed due to network or connection issues.
15 #[error("HTTP request failed: {0}")]
16 Http(#[from] reqwest::Error),
17
18 /// Failed to serialize or deserialize JSON data.
19 #[error("Serialization error: {0}")]
20 Serialization(#[from] serde_json::Error),
21
22 /// The API returned an error response.
23 ///
24 /// This includes the HTTP status code and any error message from the API.
25 #[error("API Error (Status: {status}): {message}")]
26 Api {
27 /// The HTTP status code returned by the API.
28 status: reqwest::StatusCode,
29 /// The error message from the API response body.
30 message: String,
31 },
32
33 /// Failed to parse a URL.
34 #[error("URL parsing error: {0}")]
35 Url(#[from] url::ParseError),
36
37 /// An invalid resource name was provided.
38 ///
39 /// Resource names must follow the format `resource_type/resource_id`.
40 #[error("Invalid resource name: {0}")]
41 InvalidResourceName(String),
42}
43
44/// A specialized [`Result`](std::result::Result) type for Jules API operations.
45///
46/// This type alias provides a convenient way to return results that may fail
47/// with a [`JulesError`].
48pub type Result<T> = std::result::Result<T, JulesError>;