use std::{ error, fmt, io, }; #[derive(Debug)] pub enum Error { Unknown, IO(io::Error), HTTP(reqwest::Error), HTTPStatus(reqwest::StatusCode), } impl error::Error for Error { fn source(&self) -> Option<&(dyn error::Error + 'static)> { match &self { Error::IO(io) => Some(io), _ => None } } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::IO(io) => write!(f, "io: {}", io), Error::HTTP(http) => write!(f, "http internal error: {}", http), Error::HTTPStatus(status) => write!(f, "response returned status code {}", status), _ => write!(f, "unknown error"), } } } impl From for Error { fn from(er: io::Error) -> Self { Self::IO(er) } } impl From for Error { fn from(er: reqwest::Error) -> Self { match er.status() { Some(status) => Self::HTTPStatus(status), None => Self::HTTP(er), } } }