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;
|
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)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
enum WebError {
|
enum WebError {
|
||||||
#[error("Failed to render template: {0}")]
|
|
||||||
Render(#[from] askama::Error),
|
|
||||||
#[error("Failed to validate form body: {0}")]
|
#[error("Failed to validate form body: {0}")]
|
||||||
ValidationError(#[from] validator::ValidationErrors),
|
ValidationError(#[from] validator::ValidationErrors),
|
||||||
|
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
QueryRejection(#[from] QueryRejection),
|
QueryRejection(#[from] QueryRejection),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
FormRejection(#[from] FormRejection),
|
FormRejection(#[from] FormRejection),
|
||||||
|
|
||||||
#[error("Bad request: {0}")]
|
#[error("Bad request: {0}")]
|
||||||
BadRequest(String),
|
BadRequest(String),
|
||||||
|
|
||||||
#[error("This page does not exist.")]
|
#[error("This page does not exist.")]
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
||||||
|
#[error("Failed to render template: {0}")]
|
||||||
|
Render(#[from] askama::Error),
|
||||||
#[error("Internal server error: {0}")]
|
#[error("Internal server error: {0}")]
|
||||||
InternalError(#[from] conduwuit_core::Error),
|
InternalError(#[from] conduwuit_core::Error),
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +61,7 @@ impl IntoResponse for WebError {
|
||||||
error: self,
|
error: self,
|
||||||
status,
|
status,
|
||||||
context: TemplateContext {
|
context: TemplateContext {
|
||||||
// Statically set false to prevent error pages from being indexed and to prevent
|
// Statically set false to prevent error pages from being indexed.
|
||||||
// further errors if services.config is having issues.
|
|
||||||
allow_indexing: false,
|
allow_indexing: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -67,7 +69,7 @@ impl IntoResponse for WebError {
|
||||||
if let Ok(body) = template.render() {
|
if let Ok(body) = template.render() {
|
||||||
(status, Html(body)).into_response()
|
(status, Html(body)).into_response()
|
||||||
} else {
|
} 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)]
|
#[allow(clippy::wildcard_imports)]
|
||||||
use pages::*;
|
use pages::*;
|
||||||
|
|
||||||
let sub_router = Router::new()
|
|
||||||
.merge(resources::build())
|
|
||||||
.merge(password_reset::build())
|
|
||||||
.fallback(async || WebError::NotFound);
|
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.merge(index::build())
|
.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(
|
.layer(SetResponseHeaderLayer::if_not_present(
|
||||||
header::CONTENT_SECURITY_POLICY,
|
header::CONTENT_SECURITY_POLICY,
|
||||||
HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),
|
HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue