build: add api server response envelope helpers
This commit is contained in:
@@ -2,17 +2,18 @@ use axum::{
|
||||
extract::Request,
|
||||
http::header::CONTENT_TYPE,
|
||||
middleware::Next,
|
||||
response::{IntoResponse, Response},
|
||||
response::Response,
|
||||
};
|
||||
use tracing::{error, warn};
|
||||
|
||||
use crate::{
|
||||
http_error::AppError,
|
||||
request_context::resolve_request_id,
|
||||
request_context::{resolve_request_id, RequestContext},
|
||||
};
|
||||
|
||||
pub async fn normalize_error_response(request: Request, next: Next) -> Response {
|
||||
let request_id = resolve_request_id(&request);
|
||||
let request_context = request.extensions().get::<RequestContext>().cloned();
|
||||
let response = next.run(request).await;
|
||||
|
||||
if !should_normalize_error_response(&response) {
|
||||
@@ -39,7 +40,7 @@ pub async fn normalize_error_response(request: Request, next: Next) -> Response
|
||||
);
|
||||
}
|
||||
|
||||
app_error.into_response()
|
||||
app_error.into_response_with_context(request_context.as_ref())
|
||||
}
|
||||
|
||||
fn should_normalize_error_response(response: &Response) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user