1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use Any;
use ;
use StatusCode;
use CatchPanicLayer;
/// Panic handler used internally by [`catch_panic`].
///
/// Converts a caught panic into a `500 Internal Server Error` response and
/// stores a `modo::Error` in the response extensions so that
/// [`error_handler`](super::error_handler) can rewrite it.
;
/// Returns a layer that catches panics in handlers and returns a 500 response.
///
/// The response is a bare `500 Internal Server Error` with a
/// [`crate::Error::internal`] value in its extensions, so
/// [`error_handler`](super::error_handler) can rewrite the body through
/// the application's chosen responder.
///
/// # Layer ordering
///
/// Install `catch_panic()` **outside** the handler (so it sees handler
/// panics) but **inside** [`tracing`](super::tracing) so the panic is
/// still observed in a span. If installed *inside* `error_handler` the
/// 500 response is re-rendered by the handler; if installed *outside* it
/// the raw 500 bypasses the handler.
///
/// # Example
///
/// ```rust,no_run
/// use axum::{Router, routing::get};
/// use modo::middleware::catch_panic;
///
/// let app: Router = Router::new()
/// .route("/", get(|| async { "ok" }))
/// .layer(catch_panic());
/// ```