rabbitmq_management_client/
errors.rs1use http::StatusCode;
2
3#[derive(thiserror::Error, Debug)]
4pub enum RabbitMqClientError {
5 #[error("Unauthorized")]
6 Unauthorized,
7 #[error("Missing credentials")]
8 MissingCredentials,
9 #[error("Resource already exists: {0}")]
10 AlreadyExists(String),
11 #[error("Resource not found: {0}")]
12 NotFound(String),
13 #[error("Invalid RabbitMq API url: {0}")]
14 InvalidApiUrl(String),
15 #[error("Failed to parse the API response: {0}")]
16 JSONError(#[source] serde_json::Error),
17 #[error("Failed to handle response: {0}")]
18 ResponseError(#[source] reqwest::Error),
19 #[error("Failed to execute the middleware: {0}")]
20 Middleware(#[source] anyhow::Error),
21 #[error("Failed to send the API request: {0}")]
22 Request(#[source] reqwest::Error),
23 #[error("RabbitMq API error: {0:?}")]
24 ApiError(RabbitMqApiError),
25 #[error("Unexpected API response: {0}")]
26 UnexpectedResponse(String),
27}
28
29impl From<reqwest_middleware::Error> for RabbitMqClientError {
30 fn from(value: reqwest_middleware::Error) -> Self {
31 match value {
32 reqwest_middleware::Error::Middleware(e) => RabbitMqClientError::Middleware(e),
33 reqwest_middleware::Error::Reqwest(e) => RabbitMqClientError::Request(e),
34 }
35 }
36}
37
38#[derive(Debug)]
39pub struct RabbitMqApiError {
40 pub code: StatusCode,
41 pub text: String,
42}