1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use http::Error as HttpError;
use hyper::{Error as HyperError, StatusCode};
use serde_json::Error as JsonError;
use thiserror::Error as ThisError;
use tokio::time::Elapsed;
use url::ParseError as UrlParseError;
fn strs_to_str(strs: &Vec<&'static str>) -> String {
strs.join(", ")
}
#[derive(ThisError, Debug)]
pub enum Error {
#[error("failed to parse Consul endpoint: {0:?}")]
InvalidConsulEndpoint(#[from] UrlParseError),
#[error("failed to serialize request body to JSON: {0:?}")]
InvalidRequestBody(JsonError),
#[error("failed to build request: {0:?}")]
InvalidRequest(HttpError),
#[error("request error: {0}")]
RequestError(#[from] HyperError),
#[error("request timed out: {0}")]
RequestTimedOut(#[from] Elapsed),
#[error("unexpected response: {0}")]
ResponseError(#[from] ResponseError),
}
#[derive(ThisError, Debug)]
pub enum ResponseError {
#[error("unexpected status code: {0}")]
UnexpectedStatus(StatusCode),
#[error("missing or invalid response headers: {}", strs_to_str(.0))]
InvalidHeaders(Vec<&'static str>),
#[error("failed to consume response: {0}")]
BodyConsumeFailure(#[from] HyperError),
#[error("invalid JSON payload: {0}")]
InvalidPayload(#[from] JsonError),
}