a2a_rs/adapter/error/
client.rs1use crate::domain::A2AError;
4use std::io;
5use thiserror::Error;
6
7#[derive(Error, Debug)]
9#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
10pub enum HttpClientError {
11 #[error("HTTP client error: {0}")]
13 Reqwest(#[from] reqwest::Error),
14
15 #[error("IO error: {0}")]
17 Io(#[from] io::Error),
18
19 #[error("Request error: {0}")]
21 Request(String),
22
23 #[error("Response error: {status} - {message}")]
25 Response { status: u16, message: String },
26
27 #[error("Connection timeout")]
29 Timeout,
30}
31
32#[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}