From 50c94d85a1f61416f8b4aa5e2a8f4a54a5ce68dc Mon Sep 17 00:00:00 2001 From: Ginger Date: Wed, 18 Mar 2026 13:18:53 -0400 Subject: [PATCH] fix: Code cleanup --- src/web/mod.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/web/mod.rs b/src/web/mod.rs index 41543bbc..2440df4a 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -15,22 +15,25 @@ mod pages; type State = state::State; +const CATASTROPHIC_FAILURE: &str = "cat-astrophic failure! we couldn't even render the error template. \ +please contact the team @ https://continuwuity.org"; + #[derive(Debug, thiserror::Error)] enum WebError { - #[error("Failed to render template: {0}")] - Render(#[from] askama::Error), #[error("Failed to validate form body: {0}")] ValidationError(#[from] validator::ValidationErrors), - #[error("{0}")] QueryRejection(#[from] QueryRejection), #[error("{0}")] FormRejection(#[from] FormRejection), - #[error("Bad request: {0}")] BadRequest(String), + #[error("This page does not exist.")] NotFound, + + #[error("Failed to render template: {0}")] + Render(#[from] askama::Error), #[error("Internal server error: {0}")] InternalError(#[from] conduwuit_core::Error), } @@ -58,8 +61,7 @@ impl IntoResponse for WebError { error: self, status, context: TemplateContext { - // Statically set false to prevent error pages from being indexed and to prevent - // further errors if services.config is having issues. + // Statically set false to prevent error pages from being indexed. allow_indexing: false, }, }; @@ -67,7 +69,7 @@ impl IntoResponse for WebError { if let Ok(body) = template.render() { (status, Html(body)).into_response() } else { - (status, "Something went wrong").into_response() + (status, CATASTROPHIC_FAILURE).into_response() } } } @@ -76,14 +78,15 @@ pub fn build() -> Router { #[allow(clippy::wildcard_imports)] use pages::*; - let sub_router = Router::new() - .merge(resources::build()) - .merge(password_reset::build()) - .fallback(async || WebError::NotFound); - Router::new() .merge(index::build()) - .nest("/_continuwuity/", sub_router) + .nest( + "/_continuwuity/", + Router::new() + .merge(resources::build()) + .merge(password_reset::build()) + .fallback(async || WebError::NotFound), + ) .layer(SetResponseHeaderLayer::if_not_present( header::CONTENT_SECURITY_POLICY, HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),