comfyui_client/
errors.rs

1use reqwest::StatusCode;
2use serde_json::Value;
3use tokio_tungstenite::tungstenite;
4
5/// Type alias for the result of client operations.
6pub type ClientResult<T> = Result<T, ClientError>;
7
8/// Errors that can occur during client operations.
9#[derive(thiserror::Error, Debug)]
10pub enum ClientError {
11    /// Error that occurs when parsing a URL.
12    #[error(transparent)]
13    UrlParse(#[from] url::ParseError),
14
15    /// Error that occurs during a reqwest operation.
16    #[error(transparent)]
17    Reqwest(#[from] reqwest::Error),
18
19    /// Error that occurs during a tungstenite operation.
20    #[error(transparent)]
21    Tungstenite(#[from] tungstenite::Error),
22
23    /// Error that occurs during a serde_json operation.
24    #[error(transparent)]
25    SerdeJson(#[from] serde_json::Error),
26
27    /// Error that occurs when setting the websocket scheme.
28    #[error("set websocket scheme failed")]
29    SetWsScheme,
30
31    /// Error that occurs during an API operation.
32    #[error(transparent)]
33    Api(#[from] ApiError),
34}
35
36/// Error that occurs during an API operation.
37#[derive(thiserror::Error, Debug)]
38#[error("api error")]
39pub struct ApiError {
40    /// The HTTP status code of the API response.
41    pub status: StatusCode,
42    /// The body of the API response.
43    pub body: ApiBody,
44}
45
46/// The body of an API response.
47#[derive(Debug)]
48pub enum ApiBody {
49    /// JSON body.
50    Json(Value),
51    /// Text body.
52    Text(String),
53}