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

@ -13,7 +13,7 @@ use axum::{
};
use serde::Deserialize;
use super::{error_response, strip_container_prefix, validate_agent_name};
use super::{error_response, problem_response, strip_container_prefix, validate_agent_name};
use crate::lifecycle;
#[derive(Deserialize)]
@ -48,7 +48,10 @@ pub(super) async fn get_journal(
let prefixed = format!("{}{container}", lifecycle::AGENT_PREFIX);
let live = lifecycle::list().await.unwrap_or_default();
if !live.iter().any(|c| c == &prefixed) {
return error_response(&format!("journal: no managed container {prefixed:?}"));
return problem_response(
StatusCode::NOT_FOUND,
&format!("journal: no managed container {prefixed:?}"),
);
}
let lines = q.lines.unwrap_or(500).min(5000);
let unit = match q.unit.as_deref().filter(|s| !s.is_empty()) {
@ -61,7 +64,10 @@ pub(super) async fn get_journal(
format!("{u}.service")
};
if !allowed.contains(&unit.as_str()) {
return error_response(&format!("journal: unknown unit {unit:?}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("journal: unknown unit {unit:?}"),
);
}
Some(unit)
}
@ -121,7 +127,10 @@ pub(super) async fn get_journal_host(
format!("{u}.service")
};
if !allowed.contains(&unit.as_str()) {
return error_response(&format!("journal-host: unknown unit {unit:?}"));
return problem_response(
StatusCode::BAD_REQUEST,
&format!("journal-host: unknown unit {unit:?}"),
);
}
cmd.args(["-u", &unit]);
}