buswatch_adapters/
error.rs

1//! Error types for adapters.
2
3use thiserror::Error;
4
5/// Errors that can occur when collecting metrics from adapters.
6#[derive(Debug, Error)]
7pub enum AdapterError {
8    /// HTTP request failed.
9    #[error("HTTP request failed: {0}")]
10    Http(String),
11
12    /// Failed to parse response.
13    #[error("Failed to parse response: {0}")]
14    Parse(String),
15
16    /// Authentication failed.
17    #[error("Authentication failed: {0}")]
18    Auth(String),
19
20    /// Connection failed.
21    #[error("Connection failed: {0}")]
22    Connection(String),
23
24    /// Timeout waiting for response.
25    #[error("Request timed out")]
26    Timeout,
27
28    /// Feature not supported by this message bus version.
29    #[error("Feature not supported: {0}")]
30    Unsupported(String),
31}
32
33#[cfg(feature = "rabbitmq")]
34impl From<reqwest::Error> for AdapterError {
35    fn from(err: reqwest::Error) -> Self {
36        if err.is_timeout() {
37            AdapterError::Timeout
38        } else if err.is_connect() {
39            AdapterError::Connection(err.to_string())
40        } else {
41            AdapterError::Http(err.to_string())
42        }
43    }
44}