return accurate http status codes for dashboard client errors

This commit is contained in:
damocles 2026-06-22 13:57:27 +02:00 committed by mara
commit 5dc1b3933a
7 changed files with 63 additions and 22 deletions

View file

@ -12,7 +12,7 @@ use axum::{
};
use serde::{Deserialize, Serialize};
use super::{AppState, error_response, guard_agent_name, strip_container_prefix};
use super::{AppState, guard_agent_name, problem_response, strip_container_prefix};
#[derive(Serialize)]
pub(super) struct ToolGroupsSnapshot {
@ -120,7 +120,10 @@ pub(super) async fn post_tool_groups(
// Validate group names before queuing — fail fast so the operator
// sees the error immediately rather than waiting for the worker.
if let Err(e) = crate::tool_groups::validate_groups(&body.groups) {
return error_response(&format!("invalid tool-groups for {logical}: {e}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("invalid tool-groups for {logical}: {e}"),
);
}
// Enqueue a PermChange so the JSON file write is serialised through
// the FIFO worker. Prevents concurrent batch-apply actions for
@ -204,7 +207,10 @@ pub(super) async fn post_capabilities(
.collect();
for cap in &body.caps {
if !known.contains(&cap.as_str()) {
return error_response(&format!("unknown capability: {cap}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("unknown capability: {cap}"),
);
}
}
// Enqueue a PermChange so the JSON file write is serialised through
@ -272,12 +278,18 @@ pub(super) async fn post_permissions(
if let Some(groups) = &change.tool_groups
&& let Err(e) = crate::tool_groups::validate_groups(groups)
{
return error_response(&format!("invalid tool-groups for {logical}: {e}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("invalid tool-groups for {logical}: {e}"),
);
}
if let Some(caps) = &change.capabilities {
for cap in caps {
if !known_caps.contains(&cap.as_str()) {
return error_response(&format!("unknown capability for {logical}: {cap}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("unknown capability for {logical}: {cap}"),
);
}
}
}