allowthem_server/
error.rs1use axum::http::StatusCode;
2use axum::response::{IntoResponse, Response};
3use serde_json::json;
4
5use allowthem_core::AuthError;
6
7#[derive(Debug)]
12pub enum AuthExtractError {
13 Unauthenticated,
16 Internal(AuthError),
18}
19
20impl IntoResponse for AuthExtractError {
21 fn into_response(self) -> Response {
22 match self {
23 Self::Unauthenticated => (
24 StatusCode::UNAUTHORIZED,
25 axum::Json(json!({"error": "unauthenticated"})),
26 )
27 .into_response(),
28 Self::Internal(err) => {
29 tracing::error!("auth extraction error: {err}");
30 (
31 StatusCode::INTERNAL_SERVER_ERROR,
32 axum::Json(json!({"error": "internal error"})),
33 )
34 .into_response()
35 }
36 }
37 }
38}