Trouble with CatchPanicLayer for panic handling #2108
-
OverviewI added Dependencies[dependencies]
axum = "0.6.19"
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.4.2", features = ["catch-panic"] } Codesuse axum::routing::get;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = axum::Router::new()
.route("/panic", get(|| async { panic!("panic!!") }))
.layer(tower_http::catch_panic::CatchPanicLayer::new());
axum::Server::bind(&"0.0.0.0:8080".parse()?)
.serve(app.into_make_service())
.await?;
Ok(())
} Resultswhen making a request using curl as shown below: curl http://127.0.0.1:8080/panic The application produced the following error:
In my understanding, I expected the application to return an HTTP status code 500 without crashing when encountering a panic. I apologize if my code implementation was incorrect. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Works for me. I get a |
Beta Was this translation helpful? Give feedback.
Works for me. I get a
500 Internal Server
error response and the process doesn't shutdown. The panic is still printed in the console though. Nothing tower-http can do about that.