return accurate http status codes for dashboard client errors
This commit is contained in:
parent
dc4c5460d5
commit
5dc1b3933a
7 changed files with 63 additions and 22 deletions
|
|
@ -11,7 +11,7 @@ use axum::{
|
|||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
use super::{AppState, error_response};
|
||||
use super::{AppState, error_response, problem_response};
|
||||
|
||||
/// `GET /api/schedules` — snapshot of every schedule for the
|
||||
/// scheduled-prompts tab. Returns the wire shape directly
|
||||
|
|
@ -51,13 +51,19 @@ pub(super) async fn post_schedule_new(
|
|||
axum::Json(payload): axum::Json<hive_sh4re::SchedulePromptPayload>,
|
||||
) -> Response {
|
||||
if payload.targets.is_empty() {
|
||||
return error_response("schedule must have at least one target");
|
||||
return problem_response(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"schedule must have at least one target",
|
||||
);
|
||||
}
|
||||
if payload.body.trim().is_empty() {
|
||||
return error_response("schedule body must be non-empty");
|
||||
return problem_response(StatusCode::BAD_REQUEST, "schedule body must be non-empty");
|
||||
}
|
||||
if let Some(0) = payload.interval_seconds {
|
||||
return error_response("interval_seconds must be > 0 (use None for one-shot)");
|
||||
return problem_response(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"interval_seconds must be > 0 (use None for one-shot)",
|
||||
);
|
||||
}
|
||||
let new = crate::scheduled_prompts::NewSchedule {
|
||||
owner: hive_sh4re::OPERATOR_RECIPIENT.to_owned(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue