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.
59 lines
1.3 KiB
59 lines
1.3 KiB
use std::error;
|
|
use std::fmt;
|
|
use std::net;
|
|
use std::result;
|
|
|
|
pub type Result<T> = result::Result<T, Error>;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
APIError(APIError),
|
|
Cloudflare(cloudflare::errors::Error),
|
|
AddrParseError(net::AddrParseError)
|
|
}
|
|
|
|
impl From<APIError> for Error {
|
|
fn from(err: APIError) -> Error {
|
|
Error::APIError(err)
|
|
}
|
|
}
|
|
|
|
impl From<cloudflare::errors::Error> for Error {
|
|
fn from(err: cloudflare::errors::Error) -> Error {
|
|
Error::Cloudflare(err)
|
|
}
|
|
}
|
|
|
|
impl From<net::AddrParseError> for Error {
|
|
fn from(err: net::AddrParseError) -> Error {
|
|
Error::AddrParseError(err)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct APIError {
|
|
description: String,
|
|
original_error: Option<Box<error::Error>>,
|
|
}
|
|
|
|
impl APIError {
|
|
pub fn new(description: &str, original_error: Option<Box<error::Error>>) -> Error {
|
|
Error::from(APIError {
|
|
description: String::from(description),
|
|
original_error,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl error::Error for APIError {}
|
|
|
|
impl fmt::Display for APIError {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
match &self.original_error {
|
|
Some(original_error) => {
|
|
write!(f, "{}: \"{:?}\"", self.description, original_error)
|
|
}
|
|
None => write!(f, "{}", self.description)
|
|
}
|
|
}
|
|
}
|