drogue_bazaar/auth/
error.rs

1#[cfg(feature = "actix")]
2use drogue_client::error::ErrorInformation;
3
4#[derive(Clone, Debug, thiserror::Error)]
5pub enum AuthError {
6    #[error("Forbidden")]
7    Forbidden,
8    #[error("Invalid request: {0}")]
9    InvalidRequest(String),
10    #[error("Internal: {0}")]
11    Internal(String),
12    #[error("Resource not found: {0} / {1}")]
13    NotFound(String, String),
14}
15
16#[cfg(feature = "actix")]
17impl actix_web::ResponseError for AuthError {
18    fn error_response(&self) -> actix_web::HttpResponse<actix_http::body::BoxBody> {
19        match self {
20            Self::Forbidden => actix_web::HttpResponse::Forbidden().json(ErrorInformation {
21                error: "Forbidden".to_string(),
22                message: self.to_string(),
23            }),
24            Self::InvalidRequest(_) => {
25                actix_web::HttpResponse::Forbidden().json(ErrorInformation {
26                    error: "Forbidden".to_string(),
27                    message: self.to_string(),
28                })
29            }
30            Self::Internal(_) => {
31                actix_web::HttpResponse::InternalServerError().json(ErrorInformation {
32                    error: "Internal".to_string(),
33                    message: self.to_string(),
34                })
35            }
36            Self::NotFound(..) => actix_web::HttpResponse::NotFound().json(ErrorInformation {
37                error: "NotFound".to_string(),
38                message: self.to_string(),
39            }),
40        }
41    }
42}