a2a_rs/adapter/error/
client.rs1use crate::adapter::error::describe_transport_error;
4use crate::domain::A2AError;
5use std::io;
6use thiserror::Error;
7
8#[derive(Error, Debug)]
10#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
11pub enum HttpClientError {
12 #[error("HTTP client error: {0}")]
14 Reqwest(#[from] reqwest::Error),
15
16 #[error("IO error: {0}")]
18 Io(#[from] io::Error),
19
20 #[error("Request error: {0}")]
22 Request(String),
23
24 #[error("Response error: {status} - {message}")]
26 Response { status: u16, message: String },
27
28 #[error("Connection timeout")]
30 Timeout,
31}
32
33#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
35impl From<HttpClientError> for A2AError {
36 fn from(error: HttpClientError) -> Self {
37 match error {
38 HttpClientError::Reqwest(e) => A2AError::Internal(format!(
41 "HTTP client error: {}",
42 describe_transport_error(&e)
43 )),
44 HttpClientError::Io(e) => A2AError::Io(e),
45 HttpClientError::Request(msg) => {
46 A2AError::Internal(format!("HTTP request error: {}", msg))
47 }
48 HttpClientError::Response { status, message } => {
49 A2AError::Internal(format!("HTTP response error: {} - {}", status, message))
50 }
51 HttpClientError::Timeout => A2AError::Internal("HTTP request timeout".to_string()),
52 }
53 }
54}