feat: Implement dedicated 404 page for routes under /_continuwuity/

This commit is contained in:
Ginger
2026-03-04 11:18:07 -05:00
parent 43aa172829
commit eec7103910
6 changed files with 24 additions and 14 deletions
+4 -2
View File
@@ -20,6 +20,8 @@ enum WebError {
ValidationError(#[from] validator::ValidationErrors),
#[error("Bad request: {0}")]
BadRequest(String),
#[error("This page does not exist.")]
NotFound,
#[error("Internal server error: {0}")]
InternalError(#[from] conduwuit_core::Error),
}
@@ -28,14 +30,13 @@ impl IntoResponse for WebError {
fn into_response(self) -> Response {
#[derive(Debug, Template)]
#[template(path = "error.html.j2")]
#[allow(unused)]
struct Error {
error: WebError,
status: StatusCode,
}
let status = match &self {
| Self::ValidationError(_) | Self::BadRequest(_) => StatusCode::BAD_REQUEST,
| Self::NotFound => StatusCode::NOT_FOUND,
| _ => StatusCode::INTERNAL_SERVER_ERROR,
};
@@ -57,6 +58,7 @@ pub fn build() -> Router<state::State> {
.merge(index::build())
.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:;"),