use crate::domain::A2AError;
use std::io;
use thiserror::Error;
#[derive(Error, Debug)]
#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
pub enum HttpClientError {
#[error("HTTP client error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Request error: {0}")]
Request(String),
#[error("Response error: {status} - {message}")]
Response { status: u16, message: String },
#[error("Connection timeout")]
Timeout,
}
#[cfg(any(feature = "http-client", feature = "jsonrpc-client"))]
impl From<HttpClientError> for A2AError {
fn from(error: HttpClientError) -> Self {
match error {
HttpClientError::Reqwest(e) => A2AError::Internal(format!("HTTP client error: {}", e)),
HttpClientError::Io(e) => A2AError::Io(e),
HttpClientError::Request(msg) => {
A2AError::Internal(format!("HTTP request error: {}", msg))
}
HttpClientError::Response { status, message } => {
A2AError::Internal(format!("HTTP response error: {} - {}", status, message))
}
HttpClientError::Timeout => A2AError::Internal("HTTP request timeout".to_string()),
}
}
}