From 6fdb4c25c4557aa0b59b5c4ba348ecab502cb57e Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 19 Jul 2022 03:09:37 +0300 Subject: Catch panics on requests This will allow to display a prettier error page in the future. There is a possibility of instantiating the panic handler per-module to allow for custom panic messages expressed in the same form the module itself gives error messages (e.g. pretty HTML for frontend, MicropubError for Micropub messages etc.) --- kittybox-rs/src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'kittybox-rs/src') diff --git a/kittybox-rs/src/main.rs b/kittybox-rs/src/main.rs index 59c3e69..4fb0eec 100644 --- a/kittybox-rs/src/main.rs +++ b/kittybox-rs/src/main.rs @@ -174,8 +174,8 @@ async fn main() { "/.kittybox/health", axum::routing::get( |axum::Extension(db): axum::Extension| async move { - // TODO health-check the database - "OK" + // TODO health-check the database + "OK" } ) .layer(axum::Extension(database)) @@ -195,7 +195,8 @@ async fn main() { .layer(axum::Extension(kittybox::tokenauth::TokenEndpoint(token_endpoint))) .layer(tower::ServiceBuilder::new() .layer(tower_http::trace::TraceLayer::new_for_http()) - .into_inner()); + .into_inner()) + .layer(tower_http::catch_panic::CatchPanicLayer::new()); // A little dance to turn a potential file descriptor into // a guaranteed async network socket -- cgit 1.4.1