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

@ -1657,18 +1657,23 @@ fn strip_container_prefix(name: &str) -> String {
.to_owned()
}
/// Convenience wrapper for the common internal-error case: a 500
/// RFC 9457 (`application/problem+json`) response via the
/// `problem_details` crate. `from_status_code` sets `status` + `title`
/// (the canonical reason phrase) and leaves `type` as the default
/// `about:blank`; `with_detail` carries the caller message; the crate's
/// axum `IntoResponse` emits the `application/problem+json` body the
/// frontend parses (it reads `detail`). Most dashboard handlers funnel
/// their errors through here; handlers with a more specific client
/// failure (bad input, not found) build the same `ProblemDetails`
/// inline with the right status.
fn error_response(message: &str) -> Response {
/// The common internal-error case as a `ProblemDetails`: a 500 RFC 9457
/// (`application/problem+json`) value via the `problem_details` crate.
/// `from_status_code` sets `status` + `title` (the canonical reason phrase)
/// and leaves `type` as the default `about:blank`; `with_detail` carries the
/// caller message; the crate's axum `IntoResponse` emits the
/// `application/problem+json` body the frontend parses (it reads `detail`).
/// Handlers that surface client failures return `Result<_, ProblemDetails>`
/// and hand this (or an inline `from_status_code(4xx)`) straight to `Err` —
/// no manual `.into_response()`.
fn error_problem(message: &str) -> problem_details::ProblemDetails {
problem_details::ProblemDetails::from_status_code(StatusCode::INTERNAL_SERVER_ERROR)
.with_detail(message)
.into_response()
}
/// `Response` wrapper around [`error_problem`] for the many handlers typed
/// `-> Response` whose only failure mode is a 500 — they funnel errors
/// through here rather than threading a `Result` return type.
fn error_response(message: &str) -> Response {
error_problem(message).into_response()
}