humphrey_auth/
error.rs

1//! Provides error handling capabilities to the crate.
2
3use std::error::Error;
4use std::fmt::Display;
5
6/// Represents an error with authentication.
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum AuthError {
9    /// An unknown error.
10    GenericError,
11    /// The given user could not be found.
12    UserNotFound,
13    /// The given user already exists.
14    UserAlreadyExists,
15    /// The given token does not exist or has expired.
16    InvalidToken,
17    /// A session for the given user already exists.
18    SessionAlreadyExists,
19}
20
21impl Display for AuthError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match self {
24            AuthError::GenericError => write!(f, "Unknown error"),
25            AuthError::UserNotFound => write!(f, "User not found"),
26            AuthError::UserAlreadyExists => write!(f, "User already exists"),
27            AuthError::InvalidToken => write!(f, "Invalid token"),
28            AuthError::SessionAlreadyExists => write!(f, "Session already exists"),
29        }
30    }
31}
32
33impl Error for AuthError {}