You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1003 B
58 lines
1003 B
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<io::Error> for Error
|
|
{
|
|
fn from(er: io::Error) -> Self
|
|
{
|
|
Self::IO(er)
|
|
}
|
|
}
|
|
|
|
impl From<reqwest::Error> for Error
|
|
{
|
|
fn from(er: reqwest::Error) -> Self
|
|
{
|
|
match er.status() {
|
|
Some(status) => Self::HTTPStatus(status),
|
|
None => Self::HTTP(er),
|
|
}
|
|
}
|
|
}
|