Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions crates/macro_middleware/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use axum::{
body::Body,
extract::Request,
http::{Method, Response},
http::{Method, Response, StatusCode},
middleware::Next,
};
use tracing::Instrument;

#[cfg(feature = "cloud_storage")]
pub mod cloud_storage;
Expand All @@ -19,7 +20,23 @@ mod error_handler;
pub async fn connection_drop_prevention_handler(req: Request, next: Next) -> Response<Body> {
match req.method() {
&Method::PUT | &Method::POST | &Method::PATCH | &Method::DELETE => {
tokio::task::spawn(next.run(req)).await.unwrap()
let span = tracing::Span::current();
let handle = tokio::task::spawn(next.run(req).instrument(span));

match handle.await {
Ok(response) => response,
Err(err) => {
if err.is_panic() {
tracing::error!(error=?err, "request handler panicked");
} else {
tracing::error!(error=?err, "request handler task was cancelled");
}
Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::empty())
.unwrap()
}
}
}
_ => next.run(req).await,
}
Expand Down