use std::any::Any;
use axum::response::{IntoResponse, Response};
use http::StatusCode;
use tower_http::catch_panic::CatchPanicLayer;
#[derive(Clone)]
pub struct ModoPanicHandler;
impl tower_http::catch_panic::ResponseForPanic for ModoPanicHandler {
type ResponseBody = axum::body::Body;
fn response_for_panic(
&mut self,
_err: Box<dyn Any + Send + 'static>,
) -> Response<Self::ResponseBody> {
let error = crate::error::Error::internal("internal server error");
let mut response = StatusCode::INTERNAL_SERVER_ERROR.into_response();
response.extensions_mut().insert(error);
response
}
}
pub fn catch_panic() -> CatchPanicLayer<ModoPanicHandler> {
CatchPanicLayer::custom(ModoPanicHandler)
}