use std::fmt::Debug; use std::fmt::Display; use std::fmt::Formatter; use std::result; use reqwest::header::InvalidHeaderValue; use reqwest::header::ToStrError; #[derive(Debug)] pub enum Error { Reqwest(reqwest::Error), DigestAuth(digest_auth::Error), ToStr(reqwest::header::ToStrError), InvalidHeaderValue(reqwest::header::InvalidHeaderValue), AuthHeaderMissing, RequestBuilderNotCloneable, LockPoisoned, MissingHost, } pub type Result = result::Result; impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Error::Reqwest(e) => std::fmt::Display::fmt(e, f), Error::DigestAuth(e) => std::fmt::Display::fmt(e, f), Error::ToStr(e) => std::fmt::Display::fmt(e, f), Error::InvalidHeaderValue(e) => std::fmt::Display::fmt(e, f), Error::RequestBuilderNotCloneable => write!(f, "Request body must not be a stream."), Error::AuthHeaderMissing => write!(f, "The header 'www-authenticate' is missing."), Error::LockPoisoned => write!(f, "Lock was poisoned by a panicked thread."), Error::MissingHost => write!(f, "URL has no host."), } } } impl std::error::Error for Error {} impl From for Error { fn from(e: reqwest::Error) -> Self { Error::Reqwest(e) } } impl From for Error { fn from(e: digest_auth::Error) -> Self { Error::DigestAuth(e) } } impl From for Error { fn from(e: ToStrError) -> Self { Error::ToStr(e) } } impl From for Error { fn from(e: InvalidHeaderValue) -> Self { Error::InvalidHeaderValue(e) } }