gbserver/gb-auth/src/error.rs

27 lines
639 B
Rust
Raw Normal View History

2024-12-24 13:05:54 -03:00
use gb_core::Error as CoreError;
2024-12-24 21:13:47 -03:00
use redis::RedisError;
use sqlx::Error as SqlxError;
2024-12-24 13:05:54 -03:00
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AuthError {
#[error("Invalid token")]
InvalidToken,
2024-12-24 21:13:47 -03:00
#[error("Invalid credentials")]
InvalidCredentials,
2024-12-24 13:05:54 -03:00
#[error("Database error: {0}")]
2024-12-24 21:13:47 -03:00
Database(#[from] SqlxError),
2024-12-24 13:05:54 -03:00
#[error("Redis error: {0}")]
2024-12-24 21:13:47 -03:00
Redis(#[from] RedisError),
2024-12-24 13:05:54 -03:00
#[error("Internal error: {0}")]
Internal(String),
}
impl From<CoreError> for AuthError {
fn from(err: CoreError) -> Self {
2024-12-24 21:13:47 -03:00
match err {
CoreError { .. } => AuthError::Internal(err.to_string()),
}
2024-12-24 13:05:54 -03:00
}
2024-12-24 21:13:47 -03:00
}