mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +00:00
Make sure that tracing catches all panics and shows errors better
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -3747,6 +3747,7 @@ dependencies = [
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"iri-string",
|
||||
"pin-project-lite",
|
||||
"tower",
|
||||
|
||||
@@ -93,7 +93,11 @@ sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
||||
ical = { version = "0.11", features = ["generator", "serde"] }
|
||||
toml = "0.8"
|
||||
tower = "0.5"
|
||||
tower-http = { version = "0.6", features = ["trace", "normalize-path"] }
|
||||
tower-http = { version = "0.6", features = [
|
||||
"trace",
|
||||
"normalize-path",
|
||||
"catch-panic",
|
||||
] }
|
||||
rustical_dav = { path = "./crates/dav/" }
|
||||
rustical_dav_push = { path = "./crates/dav_push/" }
|
||||
rustical_store = { path = "./crates/store/" }
|
||||
|
||||
11
src/app.rs
11
src/app.rs
@@ -10,6 +10,7 @@ use rustical_store::auth::AuthenticationProvider;
|
||||
use rustical_store::{AddressbookStore, CalendarStore, SubscriptionStore};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tower_http::catch_panic::CatchPanicLayer;
|
||||
use tower_http::classify::ServerErrorsFailureClass;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tower_sessions::cookie::SameSite;
|
||||
@@ -28,7 +29,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
oidc_config: Option<OidcConfig>,
|
||||
nextcloud_login_config: NextcloudLoginConfig,
|
||||
nextcloud_flows_state: Arc<NextcloudFlows>,
|
||||
) -> Router {
|
||||
) -> Router<()> {
|
||||
let mut router = Router::new()
|
||||
.merge(caldav_router(
|
||||
"/caldav",
|
||||
@@ -71,6 +72,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
tower_sessions::cookie::time::Duration::hours(2),
|
||||
)),
|
||||
)
|
||||
.layer(CatchPanicLayer::new())
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(|request: &Request| {
|
||||
@@ -87,8 +89,11 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
||||
.on_request(|_req: &Request, _span: &Span| {})
|
||||
.on_response(|response: &Response, _latency: Duration, span: &Span| {
|
||||
span.record("status_code", tracing::field::display(response.status()));
|
||||
|
||||
tracing::debug!("response generated")
|
||||
if response.status().is_server_error() {
|
||||
tracing::error!("status server error");
|
||||
} else if response.status().is_client_error() {
|
||||
tracing::error!("status client error");
|
||||
};
|
||||
})
|
||||
.on_failure(
|
||||
|_error: ServerErrorsFailureClass, _latency: Duration, _span: &Span| {
|
||||
|
||||
Reference in New Issue
Block a user