parent
1c13c56085
commit
6f55ad839c
14 changed files with 865 additions and 72 deletions
20
src/middleware.rs
Normal file
20
src/middleware.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use axum::{body::Body, extract::Request, middleware::Next, response::Response};
|
||||
use tracing::error;
|
||||
|
||||
pub async fn log_errors(req: Request<Body>, next: Next) -> Response {
|
||||
let method = req.method().clone();
|
||||
let uri = req.uri().clone();
|
||||
|
||||
let response = next.run(req).await;
|
||||
|
||||
if response.status().is_client_error() || response.status().is_server_error() {
|
||||
error!(
|
||||
method = ?method,
|
||||
uri = ?uri,
|
||||
status = ?response.status(),
|
||||
"Error response returned"
|
||||
);
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue