always print the details in panic catcher

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-21 18:23:37 -04:00 committed by June
parent 039e79ab1b
commit f87a012834

View file

@ -35,7 +35,7 @@ use tower_http::{
trace::{DefaultOnFailure, TraceLayer}, trace::{DefaultOnFailure, TraceLayer},
ServiceBuilderExt as _, ServiceBuilderExt as _,
}; };
use tracing::{debug, error, info, level_filters::LevelFilter, warn, Level}; use tracing::{debug, error, info, warn, Level};
use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry};
mod routes; mod routes;
@ -593,32 +593,20 @@ fn maximize_fd_limit() -> Result<(), nix::errno::Errno> {
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
fn catch_panic_layer(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_util::Full<bytes::Bytes>> { fn catch_panic_layer(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_util::Full<bytes::Bytes>> {
let details = if cfg!(debug_assertions) || LevelFilter::current() == LevelFilter::TRACE { let details = if let Some(s) = err.downcast_ref::<String>() {
if let Some(s) = err.downcast_ref::<String>() { s.clone()
s.clone() } else if let Some(s) = err.downcast_ref::<&str>() {
} else if let Some(s) = err.downcast_ref::<&str>() { s.to_string()
s.to_string()
} else {
"Unknown internal server error occurred.".to_owned()
}
} else { } else {
"Internal server error occurred.".to_owned() "Unknown internal server error occurred.".to_owned()
}; };
let body = if cfg!(debug_assertions) || LevelFilter::current() == LevelFilter::TRACE { let body = serde_json::json!({
serde_json::json!({ "errcode": "M_UNKNOWN",
"errcode": "M_UNKNOWN", "error": "M_UNKNOWN: Internal server error occurred",
"error": "M_UNKNOWN: Internal server error occurred", "details": details,
"details": details, })
}) .to_string();
.to_string()
} else {
serde_json::json!({
"errcode": "M_UNKNOWN",
"error": "M_UNKNOWN: Internal server error occurred",
})
.to_string()
};
http::Response::builder() http::Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR) .status(StatusCode::INTERNAL_SERVER_ERROR)