mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +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",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
|
"http-body-util",
|
||||||
"iri-string",
|
"iri-string",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tower",
|
"tower",
|
||||||
|
|||||||
@@ -93,7 +93,11 @@ sqlx-sqlite = { version = "0.8", features = ["bundled"] }
|
|||||||
ical = { version = "0.11", features = ["generator", "serde"] }
|
ical = { version = "0.11", features = ["generator", "serde"] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
tower = "0.5"
|
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 = { path = "./crates/dav/" }
|
||||||
rustical_dav_push = { path = "./crates/dav_push/" }
|
rustical_dav_push = { path = "./crates/dav_push/" }
|
||||||
rustical_store = { path = "./crates/store/" }
|
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 rustical_store::{AddressbookStore, CalendarStore, SubscriptionStore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
use tower_http::catch_panic::CatchPanicLayer;
|
||||||
use tower_http::classify::ServerErrorsFailureClass;
|
use tower_http::classify::ServerErrorsFailureClass;
|
||||||
use tower_http::trace::TraceLayer;
|
use tower_http::trace::TraceLayer;
|
||||||
use tower_sessions::cookie::SameSite;
|
use tower_sessions::cookie::SameSite;
|
||||||
@@ -28,7 +29,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
|||||||
oidc_config: Option<OidcConfig>,
|
oidc_config: Option<OidcConfig>,
|
||||||
nextcloud_login_config: NextcloudLoginConfig,
|
nextcloud_login_config: NextcloudLoginConfig,
|
||||||
nextcloud_flows_state: Arc<NextcloudFlows>,
|
nextcloud_flows_state: Arc<NextcloudFlows>,
|
||||||
) -> Router {
|
) -> Router<()> {
|
||||||
let mut router = Router::new()
|
let mut router = Router::new()
|
||||||
.merge(caldav_router(
|
.merge(caldav_router(
|
||||||
"/caldav",
|
"/caldav",
|
||||||
@@ -71,6 +72,7 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
|||||||
tower_sessions::cookie::time::Duration::hours(2),
|
tower_sessions::cookie::time::Duration::hours(2),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
.layer(CatchPanicLayer::new())
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
.make_span_with(|request: &Request| {
|
.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_request(|_req: &Request, _span: &Span| {})
|
||||||
.on_response(|response: &Response, _latency: Duration, span: &Span| {
|
.on_response(|response: &Response, _latency: Duration, span: &Span| {
|
||||||
span.record("status_code", tracing::field::display(response.status()));
|
span.record("status_code", tracing::field::display(response.status()));
|
||||||
|
if response.status().is_server_error() {
|
||||||
tracing::debug!("response generated")
|
tracing::error!("status server error");
|
||||||
|
} else if response.status().is_client_error() {
|
||||||
|
tracing::error!("status client error");
|
||||||
|
};
|
||||||
})
|
})
|
||||||
.on_failure(
|
.on_failure(
|
||||||
|_error: ServerErrorsFailureClass, _latency: Duration, _span: &Span| {
|
|_error: ServerErrorsFailureClass, _latency: Duration, _span: &Span| {
|
||||||
|
|||||||
Reference in New Issue
Block a user