use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde_json::json;
use allowthem_core::AuthError;
#[derive(Debug)]
pub enum AuthExtractError {
Unauthenticated,
Internal(AuthError),
}
impl IntoResponse for AuthExtractError {
fn into_response(self) -> Response {
match self {
Self::Unauthenticated => (
StatusCode::UNAUTHORIZED,
axum::Json(json!({"error": "unauthenticated"})),
)
.into_response(),
Self::Internal(err) => {
tracing::error!("auth extraction error: {err}");
(
StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(json!({"error": "internal error"})),
)
.into_response()
}
}
}
}