use std::fmt;
#[derive(Debug)]
pub enum OauthError {
InvalidUrl {
role: &'static str,
},
InsecureTransport {
role: &'static str,
},
Entropy,
StateMismatch,
Transport,
Provider {
code: String,
},
MalformedResponse,
}
impl fmt::Display for OauthError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidUrl { role } => write!(f, "{role} is not a valid URL"),
Self::InsecureTransport { role } => {
write!(
f,
"{role} must use https (http is allowed only on loopback)"
)
}
Self::Entropy => f.write_str("could not generate an unguessable OAuth state"),
Self::StateMismatch => f.write_str("OAuth state did not match"),
Self::Transport => f.write_str("the OAuth token endpoint could not be reached"),
Self::Provider { code } => write!(f, "the OAuth provider returned `{code}`"),
Self::MalformedResponse => {
f.write_str("the OAuth token endpoint returned a response that could not be parsed")
}
}
}
}
impl std::error::Error for OauthError {}