use crate::error::MppError;
use std::fmt;
#[derive(Debug)]
pub enum HttpError {
MissingChallenge,
InvalidChallenge(String),
InvalidCredential(String),
CloneFailed,
Payment(MppError),
#[cfg(feature = "client")]
Request(reqwest::Error),
}
impl fmt::Display for HttpError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MissingChallenge => {
write!(f, "402 response missing WWW-Authenticate header")
}
Self::InvalidChallenge(msg) => write!(f, "invalid challenge: {}", msg),
Self::InvalidCredential(msg) => write!(f, "invalid credential: {}", msg),
Self::CloneFailed => write!(f, "request could not be cloned for retry"),
Self::Payment(e) => write!(f, "payment failed: {}", e),
#[cfg(feature = "client")]
Self::Request(e) => write!(f, "HTTP request failed: {}", e),
}
}
}
impl std::error::Error for HttpError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Payment(e) => Some(e),
#[cfg(feature = "client")]
Self::Request(e) => Some(e),
_ => None,
}
}
}
impl From<MppError> for HttpError {
fn from(e: MppError) -> Self {
Self::Payment(e)
}
}
#[cfg(feature = "client")]
impl From<reqwest::Error> for HttpError {
fn from(e: reqwest::Error) -> Self {
Self::Request(e)
}
}