dashboard: return problem details directly from client-error handlers

This commit is contained in:
damocles 2026-06-22 15:07:57 +02:00 committed by mara
commit 65ad994c85
8 changed files with 102 additions and 100 deletions

View file

@ -12,7 +12,7 @@ use axum::{
use problem_details::ProblemDetails;
use super::{AppState, error_response};
use super::{AppState, error_problem, error_response};
pub(super) async fn api_reminders(State(state): State<AppState>) -> Response {
match state.coord.broker.list_pending_reminders() {
@ -24,17 +24,18 @@ pub(super) async fn api_reminders(State(state): State<AppState>) -> Response {
pub(super) async fn post_cancel_reminder(
State(state): State<AppState>,
AxumPath(id): AxumPath<i64>,
) -> Response {
) -> Result<Response, ProblemDetails> {
match state.coord.broker.cancel_reminder(id) {
Ok(0) => ProblemDetails::from_status_code(StatusCode::NOT_FOUND)
.with_detail(format!("reminder {id} not pending (already delivered?)"))
.into_response(),
Ok(0) => Err(ProblemDetails::from_status_code(StatusCode::NOT_FOUND)
.with_detail(format!("reminder {id} not pending (already delivered?)"))),
Ok(_) => {
tracing::info!(%id, "operator cancelled reminder");
state.coord.emit_reminders_snapshot();
(StatusCode::OK, "ok").into_response()
Ok((StatusCode::OK, "ok").into_response())
}
Err(e) => error_response(&format!("cancel reminder {id} failed: {e:#}")),
Err(e) => Err(error_problem(&format!(
"cancel reminder {id} failed: {e:#}"
))),
}
}
@ -46,16 +47,15 @@ pub(super) async fn post_cancel_reminder(
pub(super) async fn post_retry_reminder(
State(state): State<AppState>,
AxumPath(id): AxumPath<i64>,
) -> Response {
) -> Result<Response, ProblemDetails> {
match state.coord.broker.reset_reminder_failure(id) {
Ok(0) => ProblemDetails::from_status_code(StatusCode::NOT_FOUND)
.with_detail(format!("reminder {id} not pending (already delivered?)"))
.into_response(),
Ok(0) => Err(ProblemDetails::from_status_code(StatusCode::NOT_FOUND)
.with_detail(format!("reminder {id} not pending (already delivered?)"))),
Ok(_) => {
tracing::info!(%id, "operator reset reminder failure for retry");
state.coord.emit_reminders_snapshot();
(StatusCode::OK, "ok").into_response()
Ok((StatusCode::OK, "ok").into_response())
}
Err(e) => error_response(&format!("retry reminder {id} failed: {e:#}")),
Err(e) => Err(error_problem(&format!("retry reminder {id} failed: {e:#}"))),
}
}