asoiaf_api/
error.rs

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
30
31
32
33
34
use std::fmt::{self, Display, Formatter};

#[derive(Debug)]
pub enum Error {
    RequestError(reqwest::Error),
    ParseError(serde_json::Error),
    NoMorePages,
    CacheMiss,
}

impl From<reqwest::Error> for Error {
    fn from(error: reqwest::Error) -> Self {
        Error::RequestError(error)
    }
}

impl From<serde_json::Error> for Error {
    fn from(error: serde_json::Error) -> Self {
        Error::ParseError(error)
    }
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        match self {
            Error::RequestError(error) => write!(f, "RequestError: {}", error),
            Error::ParseError(error) => write!(f, "ParseError: {}", error),
            Error::NoMorePages => write!(f, "NoMorePages"),
            Error::CacheMiss => write!(f, "CacheMiss"),
        }
    }
}

impl std::error::Error for Error {}