Skip to main content

oneiros_client/
error.rs

1use std::sync::Arc;
2
3#[derive(Debug, Clone, thiserror::Error)]
4#[error(transparent)]
5pub struct ConnectionError(pub Arc<hyper::Error>);
6
7impl From<hyper::Error> for ConnectionError {
8    fn from(error: hyper::Error) -> Self {
9        Self(Arc::new(error))
10    }
11}
12
13#[derive(Debug, Clone, thiserror::Error)]
14pub enum RequestError {
15    #[error("{0}")]
16    Hyper(Arc<hyper::Error>),
17    #[error("{0}")]
18    Http(Arc<hyper::http::Error>),
19}
20
21impl From<hyper::Error> for RequestError {
22    fn from(error: hyper::Error) -> Self {
23        Self::Hyper(Arc::new(error))
24    }
25}
26
27impl From<hyper::http::Error> for RequestError {
28    fn from(error: hyper::http::Error) -> Self {
29        Self::Http(Arc::new(error))
30    }
31}
32
33#[derive(Debug, thiserror::Error)]
34#[error("service returned {status}: {body}")]
35pub struct ResponseError {
36    pub status: u16,
37    pub body: String,
38}
39
40#[derive(Debug, thiserror::Error)]
41pub enum Error {
42    #[error(transparent)]
43    Connection(#[from] ConnectionError),
44
45    #[error(transparent)]
46    Request(#[from] RequestError),
47
48    #[error(transparent)]
49    ServiceResponse(#[from] ResponseError),
50
51    #[error("Failed to deserialize response: {0}")]
52    Deserialization(#[from] serde_json::Error),
53
54    #[error("IO error: {0}")]
55    Io(#[from] std::io::Error),
56}