1use thiserror::Error;
4
5#[derive(Debug, Error)]
16pub enum AuthError {
17 #[error("no authentication token provided")]
19 MissingToken,
20
21 #[error("invalid or expired token")]
23 InvalidToken,
24
25 #[error("jwt error: {0}")]
27 Jwt(#[from] jsonwebtoken::errors::Error),
28
29 #[error("password hashing error")]
31 PasswordHash,
32
33 #[error("invalid credentials")]
35 InvalidCredentials,
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn error_display() {
44 assert_eq!(
45 AuthError::MissingToken.to_string(),
46 "no authentication token provided"
47 );
48 assert_eq!(
49 AuthError::InvalidToken.to_string(),
50 "invalid or expired token"
51 );
52 assert_eq!(
53 AuthError::InvalidCredentials.to_string(),
54 "invalid credentials"
55 );
56 }
57}