#[cfg(feature = "axum-integration")]
pub mod axum_integration {
use axum::http::HeaderMap;
use axum::response::{IntoResponse, Response};
use axum::http::StatusCode;
use crate::common::error::{JwtError, PublicJwtError};
use crate::integration::Headers;
impl Headers for HeaderMap {
fn get(&self, name: &str) -> Option<&str> {
self.get(name).and_then(|v| v.to_str().ok())
}
}
pub trait JwtErrorResponse {
fn into_response(self) -> Response;
}
impl JwtErrorResponse for JwtError {
fn into_response(self) -> Response {
let public_error: PublicJwtError = self.into();
public_error.into_response()
}
}
impl IntoResponse for PublicJwtError {
fn into_response(self) -> Response {
let status_code = StatusCode::UNAUTHORIZED;
let body = serde_json::json!({
"error": self.to_string(),
"status": "error",
"code": status_code.as_u16()
});
(status_code, axum::Json(body)).into_response()
}
}
}