server_common/error/
auth.rs1use axum::{
2 http::StatusCode,
3 response::{IntoResponse, Response},
4};
5
6#[derive(Debug)]
8pub enum AuthError {
9 InvalidToken,
10 MissingToken,
11 ExpiredToken,
12 InsufficientPermissions,
13}
14
15impl IntoResponse for AuthError {
17 fn into_response(self) -> Response {
18 let (status, error_message) = match self {
19 AuthError::InvalidToken => (StatusCode::UNAUTHORIZED, "Invalid token"),
20 AuthError::MissingToken => (StatusCode::UNAUTHORIZED, "Missing authentication token"),
21 AuthError::ExpiredToken => (StatusCode::UNAUTHORIZED, "Token has expired"),
22 AuthError::InsufficientPermissions => {
23 (StatusCode::FORBIDDEN, "Insufficient permissions")
24 }
25 };
26
27 (status, error_message).into_response()
28 }
29}