dashboard: error_response takes &str

This commit is contained in:
müde 2026-05-15 00:06:51 +02:00
parent c82d41728c
commit 46ff9c7aee
2 changed files with 11 additions and 4 deletions

7
Cargo.lock generated
View file

@ -325,6 +325,7 @@ dependencies = [
"rusqlite", "rusqlite",
"serde", "serde",
"serde_json", "serde_json",
"similar",
"tokio", "tokio",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
@ -681,6 +682,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "similar"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.12" version = "0.4.12"

View file

@ -67,23 +67,23 @@ async fn post_approve(
) -> Response { ) -> Response {
match actions::approve(&state.coord, id).await { match actions::approve(&state.coord, id).await {
Ok(()) => Redirect::to("/").into_response(), Ok(()) => Redirect::to("/").into_response(),
Err(e) => error_response(format!("approve {id} failed: {e:#}")), Err(e) => error_response(&format!("approve {id} failed: {e:#}")),
} }
} }
async fn post_deny(State(state): State<AppState>, AxumPath(id): AxumPath<i64>) -> Response { async fn post_deny(State(state): State<AppState>, AxumPath(id): AxumPath<i64>) -> Response {
match actions::deny(&state.coord, id) { match actions::deny(&state.coord, id) {
Ok(()) => Redirect::to("/").into_response(), Ok(()) => Redirect::to("/").into_response(),
Err(e) => error_response(format!("deny {id} failed: {e:#}")), Err(e) => error_response(&format!("deny {id} failed: {e:#}")),
} }
} }
fn error_response(message: String) -> Response { fn error_response(message: &str) -> Response {
( (
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
Html(format!( Html(format!(
"<!doctype html>\n<html>\n<head>{STYLE}</head>\n<body>{BANNER}\n<h2>◆ ERR0R ◆</h2>\n<pre class=\"diff\">{message}</pre>\n<p><a href=\"/\">← back</a></p>\n</body></html>", "<!doctype html>\n<html>\n<head>{STYLE}</head>\n<body>{BANNER}\n<h2>◆ ERR0R ◆</h2>\n<pre class=\"diff\">{message}</pre>\n<p><a href=\"/\">← back</a></p>\n</body></html>",
message = html_escape(&message), message = html_escape(message),
)), )),
) )
.into_response() .into_response()