mahjong_service/auth/
errors.rs1use std::fmt::Display;
2
3use actix_web::{HttpResponse, ResponseError};
4
5#[derive(Debug)]
6pub struct UnauthorizedError;
7#[derive(Debug)]
8pub enum AuthInfoSummaryError {
9 DatabaseError,
10 Unauthorized,
11}
12
13impl Display for UnauthorizedError {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 write!(f, "Unauthorized")
16 }
17}
18
19impl ResponseError for UnauthorizedError {
20 fn error_response(&self) -> HttpResponse {
21 HttpResponse::Unauthorized().body("Unauthorized")
22 }
23}
24
25impl Display for AuthInfoSummaryError {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::DatabaseError => write!(f, "Database error"),
29 Self::Unauthorized => write!(f, "Unauthorized"),
30 }
31 }
32}
33
34impl ResponseError for AuthInfoSummaryError {
35 fn error_response(&self) -> HttpResponse {
36 match self {
37 Self::DatabaseError => HttpResponse::InternalServerError().body("Database error"),
38 Self::Unauthorized => HttpResponse::Unauthorized().body("Unauthorized"),
39 }
40 }
41}