1use thiserror;
2
3use reqwest::{self, StatusCode};
4
5#[derive(thiserror::Error, Debug)]
6pub enum Error {
7 #[error("Failed to read the 'default_labels' object from the JSON file, does it exist by this name?. Parse error: {0}")]
8 DefaultLabelsError(serde_json::Error),
9 #[error("Failed to read the 'resource_labels' object from the JSON file, does it exist by this name?. Parse error: {0}")]
10 ResourceLabelsError(serde_json::Error),
11 #[error("Serde JSON serialization failed with context '{context}'. Error: {source}")]
12 ShipperSerializeError {
13 context: String,
14 source: serde_json::Error,
15 },
16 #[error("Reqwest error with context '{context}'. Error: {source}")]
17 ShipperReqwestError {
18 context: String,
19 source: reqwest::Error,
20 },
21 #[error("No 'access_token' found in the metadata server response body")]
22 ShipperTokenNotFound,
23 #[error("No 'expires_in' found in the metadata server response body")]
24 ShipperTokenExpiryNotFound,
25 #[error("unsuccessful HTTP response error with context '{context}'. HTTP status code: '{status}', body: '{body}'")]
26 HttpResponseError {
27 context: String,
28 status: StatusCode,
29 body: String,
30 },
31}
32
33impl From<reqwest::Error> for Error {
34 fn from(err: reqwest::Error) -> Self {
35 Self::ShipperReqwestError {
36 context: "Error sending HTTP request".to_string(),
37 source: err,
38 }
39 }
40}