Skip to main content

a2a_rs/adapter/error/
server.rs

1//! Error types for server adapters
2
3#[cfg(feature = "http-server")]
4use std::io;
5
6#[cfg(feature = "http-server")]
7use thiserror::Error;
8
9/// Error type for HTTP server adapter
10#[derive(Error, Debug)]
11#[cfg(feature = "http-server")]
12pub enum HttpServerError {
13    /// HTTP server error
14    #[error("HTTP server error: {0}")]
15    Server(String),
16
17    /// IO error during HTTP operations
18    #[error("IO error: {0}")]
19    Io(#[from] io::Error),
20
21    /// JSON serialization error
22    #[error("JSON serialization error: {0}")]
23    Json(#[from] serde_json::Error),
24
25    /// Invalid request format
26    #[error("Invalid request format: {0}")]
27    InvalidRequest(String),
28}
29
30// Conversion from adapter errors to domain errors
31#[cfg(feature = "http-server")]
32impl From<HttpServerError> for crate::domain::A2AError {
33    fn from(error: HttpServerError) -> Self {
34        match error {
35            HttpServerError::Server(msg) => {
36                crate::domain::A2AError::Internal(format!("HTTP server error: {}", msg))
37            }
38            HttpServerError::Io(e) => crate::domain::A2AError::Io(e),
39            HttpServerError::Json(e) => crate::domain::A2AError::JsonParse(e),
40            HttpServerError::InvalidRequest(msg) => crate::domain::A2AError::InvalidRequest(msg),
41        }
42    }
43}