fix: Code cleanup
This commit is contained in:
parent
0cc188f62c
commit
50c94d85a1
1 changed files with 16 additions and 13 deletions
|
|
@ -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<state::State> {
|
|||
#[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:;"),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue