basispoort_sync_client/
error.rs

1use std::{io, path::PathBuf};
2
3use serde::Deserialize;
4use thiserror::Error;
5use url::Url;
6
7#[non_exhaustive]
8#[derive(Error, Debug)]
9pub enum Error {
10    /// Failed to open identity certificate file at the specified path.
11    #[error("failed to open identity certificate file at '{path}'")]
12    OpenIdentityCertFile {
13        path: PathBuf,
14        #[source]
15        source: io::Error,
16    },
17
18    /// Failed to read identity certificate file at the specified path.
19    #[error("failed to read identity certificate file at '{path}'")]
20    ReadIdentityCertFile {
21        path: PathBuf,
22        #[source]
23        source: io::Error,
24    },
25
26    /// Failed parsing identity certificate file at the specified path.
27    #[error("failed parsing identity certificate file at '{path}'")]
28    ParseIdentityCertFile {
29        path: PathBuf,
30        #[source]
31        source: reqwest::Error,
32    },
33
34    /// Failed building request client.
35    #[error("failed building request client")]
36    BuildRequestClient(#[source] reqwest::Error),
37
38    /// Failed to parse URL.
39    #[error("failed to parse URL")]
40    ParseUrl {
41        url: String,
42        #[source]
43        source: url::ParseError,
44    },
45
46    /// Failed to open icon file at the specified path.
47    #[error("failed to open icon file at '{path}'")]
48    OpenIconFile {
49        path: PathBuf,
50        #[source]
51        source: io::Error,
52    },
53
54    /// Failed to read icon file at the specified path.
55    #[error("failed to read icon file at '{path}'")]
56    ReadIconFile {
57        path: PathBuf,
58        #[source]
59        source: io::Error,
60    },
61
62    /// Failed to encode payload.
63    #[error("failed to encode payload")]
64    // TODO: Useful information to pass here?
65    EncodePayload(#[source] serde_json::Error),
66
67    /// HTTP request error.
68    #[error("HTTP request error")]
69    HttpRequest(#[source] reqwest::Error),
70
71    /// HTTP response error.
72    #[error("HTTP response error")]
73    HttpResponse {
74        url: Url,
75        status: reqwest::StatusCode,
76        error_response: ErrorResponse,
77        #[source]
78        source: reqwest::Error,
79    },
80
81    /// Failed receiving the server's response body.
82    #[error("failed receiving the server's response body")]
83    ReceiveResponseBody(#[source] reqwest::Error),
84
85    /// Failed decoding the server's response body.
86    #[error("failed decoding the server's response body")]
87    DeserializeResponseBody(#[source] serde_json::Error),
88
89    /// Failed to url-encode the search predicate.
90    #[error("failed to url-encode the search predicate")]
91    SerializeSearchPredicate(#[source] serde_urlencoded::ser::Error),
92}
93
94#[derive(Debug, Deserialize)]
95pub enum ErrorResponse {
96    JSON(serde_json::Value),
97    Plain(String),
98}