rs_consul/
errors.rs

1use thiserror::Error;
2
3pub(crate) type Result<T> = std::result::Result<T, ConsulError>;
4
5/// The error type returned from all calls into this crate.
6#[derive(Debug, Error)]
7pub enum ConsulError {
8    /// The request was invalid and could not be serialized to valid json.
9    #[error("Invalid request: {0}")]
10    InvalidRequest(#[source] serde_json::Error),
11
12    /// The request was invalid and could not be converted into a proper http request.
13    #[error("Request error: {0}")]
14    RequestError(#[source] http::Error),
15
16    /// The consul server response could not be converted into a proper http response.
17    #[error("Response error: {0}")]
18    ResponseError(#[source] hyper_util::client::legacy::Error),
19
20    /// The consul server response was invalid.
21    #[error("Invalid response: {0}")]
22    InvalidResponse(#[source] hyper::Error),
23
24    /// The consul server response could not be deserialized from json.
25    #[error("Response deserialization failed: {0}")]
26    ResponseDeserializationFailed(#[source] serde_json::Error),
27
28    /// The consul server response could not be deserialized from bytes.
29    #[error("Response string deserialization failed: {0}")]
30    ResponseStringDeserializationFailed(#[source] std::str::Utf8Error),
31
32    /// The consul server response was something other than 200.
33    #[error("Unexpected response code: {0}, body: {1:?}")]
34    UnexpectedResponseCode(hyper::http::StatusCode, Option<String>),
35
36    /// The consul server refused a lock acquisition.
37    #[error("Lock acquisition failure: {0}")]
38    LockAcquisitionFailure(u64),
39
40    /// Consul returned invalid UTF8.
41    #[error("Invalid UTF8: {0}")]
42    InvalidUtf8(#[from] std::str::Utf8Error),
43
44    /// Consul returned invalid base64.
45    #[error("Invalid base64: {0}")]
46    InvalidBase64(#[from] base64::DecodeError),
47
48    /// IO error from sync api.
49    #[error("Sync IO error: {0}")]
50    SyncIoError(#[from] std::io::Error),
51
52    /// Response parse error from sync api.
53    #[error("Sync invalid response error: {0}")]
54    SyncInvalidResponseError(#[from] std::str::ParseBoolError),
55
56    /// Unexpected response code from sync api.
57    #[error("Sync unexpected response code: {0}, body: {1}")]
58    SyncUnexpectedResponseCode(u16, String),
59
60    /// Consul request exceeded specified timeout.
61    #[error("Consul request exceeded timeout of {0:?}")]
62    TimeoutExceeded(std::time::Duration),
63
64    /// Unable to resolve the service's instances in Consul.
65    #[error(
66        "Unable to resolve service '{0}' to a concrete list of addresses and ports for its instances via consul."
67    )]
68    ServiceInstanceResolutionFailed(String),
69
70    /// An error from ureq occurred.
71    #[error("UReq error: {0}")]
72    UReqError(#[from] ureq::Error),
73
74    /// Failed to delete Token.
75    #[error("Failed to delete the token")]
76    TokenDeleteFailed,
77}