mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
feat: Implement dedicated 404 page for routes under /_continuwuity/
This commit is contained in:
+4
-2
@@ -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:;"),
|
||||
|
||||
Reference in New Issue
Block a user