Skip to main content

ironflow_auth/
error.rs

1//! Authentication error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during authentication operations.
6///
7/// # Examples
8///
9/// ```
10/// use ironflow_auth::error::AuthError;
11///
12/// let err = AuthError::MissingToken;
13/// assert_eq!(err.to_string(), "no authentication token provided");
14/// ```
15#[derive(Debug, Error)]
16pub enum AuthError {
17    /// No token was provided in the request.
18    #[error("no authentication token provided")]
19    MissingToken,
20
21    /// The provided token is invalid or expired.
22    #[error("invalid or expired token")]
23    InvalidToken,
24
25    /// JWT encoding/decoding failed.
26    #[error("jwt error: {0}")]
27    Jwt(#[from] jsonwebtoken::errors::Error),
28
29    /// Password hashing failed.
30    #[error("password hashing error")]
31    PasswordHash,
32
33    /// Password verification failed (wrong password).
34    #[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}