#[derive(Clone, Copy, PartialEq)]
pub enum CheckpwnError {
StatusCode,
Network,
Decoding,
BadResponse,
InvalidApiKey,
MissingApiKey,
EmptyInput,
}
impl AsRef<str> for CheckpwnError {
fn as_ref(&self) -> &str {
match *self {
CheckpwnError::StatusCode => "Unrecognized status code received",
CheckpwnError::Network => "Failed to send request to HIBP",
CheckpwnError::Decoding => "Failed to decode response from HIBP",
CheckpwnError::BadResponse => {
"Received a bad response from HIBP - make sure the account is valid"
}
CheckpwnError::InvalidApiKey => "HIBP deemed the current API key invalid",
CheckpwnError::MissingApiKey => "The API key is missing",
CheckpwnError::EmptyInput => "Empty input that should NOT be empty",
}
}
}
impl std::fmt::Display for CheckpwnError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_ref())
}
}
impl std::fmt::Debug for CheckpwnError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_ref())
}
}
impl std::error::Error for CheckpwnError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}