feat: add many things

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2026-03-08 23:00:03 +01:00
parent 45353089c2
commit 5a5f9a3003
104 changed files with 23417 additions and 2027 deletions

View File

@@ -1,4 +1,5 @@
mod auth;
mod events;
mod pages;
mod platform;
@@ -14,10 +15,22 @@ pub fn router() -> Router<AppState> {
.merge(pages::router())
.merge(auth::router())
.merge(platform::router())
.merge(events::router())
}
/// Render an error page with the given status code, heading, and message.
fn error_page(state: &AppState, status: StatusCode, heading: &str, message: &str) -> Response {
error_page_detail(state, status, heading, message, None)
}
/// Render an error page with optional error detail (shown in a collapsible section).
fn error_page_detail(
state: &AppState,
status: StatusCode,
heading: &str,
message: &str,
detail: Option<&str>,
) -> Response {
let html = state.templates.render(
"pages/error.html.jinja",
context! {
@@ -26,6 +39,7 @@ fn error_page(state: &AppState, status: StatusCode, heading: &str, message: &str
status => status.as_u16(),
heading => heading,
message => message,
detail => detail,
},
);
match html {
@@ -33,3 +47,28 @@ fn error_page(state: &AppState, status: StatusCode, heading: &str, message: &str
Err(_) => status.into_response(),
}
}
/// Log an error and render a 500 page with the error detail.
fn internal_error(state: &AppState, context: &str, err: &dyn std::fmt::Display) -> Response {
let detail = format!("{err:#}");
tracing::error!("{context}: {detail}");
error_page_detail(
state,
StatusCode::INTERNAL_SERVER_ERROR,
"Something went wrong",
"An internal error occurred. Please try again.",
Some(&detail),
)
}
/// Log a warning for a failed call and return the default value.
/// Use for supplementary data where graceful degradation is acceptable.
fn warn_default<T: Default>(context: &str, result: Result<T, impl std::fmt::Display>) -> T {
match result {
Ok(v) => v,
Err(e) => {
tracing::warn!("{context}: {e:#}");
T::default()
}
}
}