use thiserror::Error;
#[derive(Debug, Error)]
pub enum AuthError {
#[error("no authentication token provided")]
MissingToken,
#[error("invalid or expired token")]
InvalidToken,
#[error("jwt error: {0}")]
Jwt(#[from] jsonwebtoken::errors::Error),
#[error("password hashing error")]
PasswordHash,
#[error("invalid credentials")]
InvalidCredentials,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
assert_eq!(
AuthError::MissingToken.to_string(),
"no authentication token provided"
);
assert_eq!(
AuthError::InvalidToken.to_string(),
"invalid or expired token"
);
assert_eq!(
AuthError::InvalidCredentials.to_string(),
"invalid credentials"
);
}
}