Skip to main content

agentkit_http/
error.rs

1use std::error::Error as StdError;
2
3use thiserror::Error;
4
5pub type BoxError = Box<dyn StdError + Send + Sync>;
6
7#[derive(Debug, Error)]
8pub enum HttpError {
9    #[error("invalid URL: {0}")]
10    InvalidUrl(String),
11
12    #[error("invalid header: {0}")]
13    InvalidHeader(String),
14
15    #[error("request body serialization failed: {0}")]
16    Serialize(#[source] serde_json::Error),
17
18    #[error("response body deserialization failed: {0}")]
19    Deserialize(#[source] serde_json::Error),
20
21    #[error("request failed: {0}")]
22    Request(#[source] BoxError),
23
24    #[error("response body read failed: {0}")]
25    Body(#[source] BoxError),
26
27    #[error("{0}")]
28    Other(String),
29}
30
31impl HttpError {
32    pub fn request<E>(err: E) -> Self
33    where
34        E: StdError + Send + Sync + 'static,
35    {
36        Self::Request(Box::new(err))
37    }
38
39    pub fn body<E>(err: E) -> Self
40    where
41        E: StdError + Send + Sync + 'static,
42    {
43        Self::Body(Box::new(err))
44    }
45}