tensorlake/error.rs
1//! # SDK Error Types
2//!
3//! This module provides comprehensive error handling for the Tensorlake Cloud SDK.
4//! It includes a general `SdkError` type that encompasses all possible error scenarios
5//! across the different clients, including authentication and authorization errors.
6
7use thiserror::Error;
8
9use crate::{
10 applications::error::ApplicationsError, images::error::ImagesError,
11 secrets::error::SecretsError,
12};
13
14/// The main error type for the Tensorlake Cloud SDK.
15///
16/// This enum encompasses all possible errors that can occur when using the SDK,
17/// including client-specific errors, authentication issues, and general HTTP errors.
18#[derive(Debug, Error)]
19pub enum SdkError {
20 /// Errors specific to the Applications client
21 #[error(transparent)]
22 Applications(#[from] ApplicationsError),
23
24 /// Authentication error (HTTP 401)
25 #[error("Authentication failed: {0}")]
26 Authentication(String),
27
28 /// Authorization error (HTTP 403)
29 #[error("Authorization failed: {0}")]
30 Authorization(String),
31
32 /// General HTTP errors
33 #[error(transparent)]
34 Http(#[from] reqwest::Error),
35
36 /// Reqwest middleware errors
37 #[error(transparent)]
38 Middleware(#[from] reqwest_middleware::Error),
39
40 /// Errors specific to the Images client
41 #[error(transparent)]
42 Images(#[from] ImagesError),
43
44 /// Invalid header value during client initialization
45 #[error("Invalid header value: {0}")]
46 InvalidHeaderValue(String),
47
48 /// Client configuration error
49 #[error("Client error: {0}")]
50 ClientError(String),
51
52 /// General IO errors
53 #[error(transparent)]
54 Io(#[from] std::io::Error),
55
56 /// JSON serialization/deserialization errors
57 #[error(transparent)]
58 Json(#[from] serde_json::Error),
59
60 /// JSON serialization/deserialization errors
61 #[error(transparent)]
62 JsonWithError(#[from] serde_path_to_error::Error<serde_json::Error>),
63
64 /// Errors specific to the Secrets client
65 #[error(transparent)]
66 Secrets(#[from] SecretsError),
67
68 /// Server returned an error status
69 #[error("Server error: {status} - {message}")]
70 ServerError {
71 status: reqwest::StatusCode,
72 message: String,
73 },
74
75 /// EventSource (SSE) stream error
76 #[error("EventSource error: {0}")]
77 EventSourceError(String),
78}