Module salvo_extra::catch_panic
source · Available on crate feature
catch-panic
only.Expand description
Middleware for catch panic in handlers.
This middleware catches panics and write 500 Internal Server Error
into response.
This middleware should be used as the first middleware.
§Example
use salvo_core::prelude::*;
use salvo_extra::catch_panic::CatchPanic;
#[handler]
async fn hello() {
panic!("panic error!");
}
#[tokio::main]
async fn main() {
let router = Router::new().hoop(CatchPanic::new()).get(hello);
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(router).await;
}
Structs§
- Middleware for catch panic in handlers.