1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use bytes::Bytes;

pub enum Error<T> {
    Item(T),
    Reqwest(reqwest::Error),
    Serde(serde_json::Error),
    Unexpected {
        code: u16,
        data: Bytes,
    }
}

impl<T> Error<T> {
    pub fn unexpected(code: u16, data: Bytes) -> Error<T> {
        Error::Unexpected { code, data }
    }
}

impl<T> From<reqwest::Error> for Error<T> {
    fn from(value: reqwest::Error) -> Self {
        Error::Reqwest(value)
    }
}

impl<T> From<serde_json::Error> for Error<T> {
    fn from(value: serde_json::Error) -> Self {
        Error::Serde(value)
    }
}