Skip to main content

a2a_rs/adapter/error/
client.rs

1//! Error types for client adapters
2
3use crate::domain::A2AError;
4use std::io;
5use thiserror::Error;
6
7/// Error type for HTTP client adapter
8#[derive(Error, Debug)]
9#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
10pub enum HttpClientError {
11    /// Reqwest client error
12    #[error("HTTP client error: {0}")]
13    Reqwest(#[from] reqwest::Error),
14
15    /// IO error during HTTP operations
16    #[error("IO error: {0}")]
17    Io(#[from] io::Error),
18
19    /// Error during request processing
20    #[error("Request error: {0}")]
21    Request(String),
22
23    /// Error with HTTP response
24    #[error("Response error: {status} - {message}")]
25    Response { status: u16, message: String },
26
27    /// Connection timeout
28    #[error("Connection timeout")]
29    Timeout,
30}
31
32// Conversion from adapter errors to domain errors
33#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
34impl From<HttpClientError> for A2AError {
35    fn from(error: HttpClientError) -> Self {
36        match error {
37            HttpClientError::Reqwest(e) => A2AError::Internal(format!("HTTP client error: {}", e)),
38            HttpClientError::Io(e) => A2AError::Io(e),
39            HttpClientError::Request(msg) => {
40                A2AError::Internal(format!("HTTP request error: {}", msg))
41            }
42            HttpClientError::Response { status, message } => {
43                A2AError::Internal(format!("HTTP response error: {} - {}", status, message))
44            }
45            HttpClientError::Timeout => A2AError::Internal("HTTP request timeout".to_string()),
46        }
47    }
48}