miryad_core/auth/
error.rs1use axum::http::StatusCode;
2use axum::response::{IntoResponse, Response};
3
4#[derive(Debug, thiserror::Error)]
5pub enum AuthError {
6 #[error("MRD-AUTH-001: not authenticated (no session cookie)")]
7 NotAuthenticated,
8 #[error("MRD-AUTH-002: invalid or expired session")]
9 InvalidSession,
10 #[error("MRD-AUTH-003: OIDC error: {0}")]
11 Oidc(String),
12 #[error("MRD-AUTH-014: invalid or unknown API token")]
13 InvalidToken,
14 #[error("MRD-AUTH-015: expired API token")]
15 TokenExpired,
16 #[error("MRD-AUTH-016: database error: {0}")]
17 Database(#[from] sea_orm::DbErr),
18}
19
20impl IntoResponse for AuthError {
21 fn into_response(self) -> Response {
22 let status = match self {
23 AuthError::NotAuthenticated | AuthError::InvalidSession => StatusCode::UNAUTHORIZED,
24 AuthError::Oidc(_) => StatusCode::BAD_GATEWAY,
25 AuthError::InvalidToken | AuthError::TokenExpired => StatusCode::UNAUTHORIZED,
26 AuthError::Database(_) => StatusCode::INTERNAL_SERVER_ERROR,
27 };
28 (status, self.to_string()).into_response()
29 }
30}