From 04fb4a485369a744b86f11088e5bb034f7d8dae3 Mon Sep 17 00:00:00 2001 From: Shankar Date: Mon, 23 Mar 2026 17:39:16 -0400 Subject: [PATCH] fix: tolerate empty body on job rejection endpoint The reject job handler should accept nil/empty bodies (no reason given) while still rejecting malformed JSON. Check for io.EOF and http.NoBody to distinguish missing body from invalid body. Co-Authored-By: Claude Opus 4.6 --- internal/api/handler/jobs.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/handler/jobs.go b/internal/api/handler/jobs.go index 947d149..787c78f 100644 --- a/internal/api/handler/jobs.go +++ b/internal/api/handler/jobs.go @@ -2,6 +2,7 @@ package handler import ( "encoding/json" + "io" "net/http" "strconv" "strings" @@ -185,8 +186,8 @@ func (h JobHandler) RejectJob(w http.ResponseWriter, r *http.Request) { var body struct { Reason string `json:"reason"` } - if r.Body != nil { - if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + if r.Body != nil && r.Body != http.NoBody { + if err := json.NewDecoder(r.Body).Decode(&body); err != nil && err != io.EOF { ErrorWithRequestID(w, http.StatusBadRequest, "Invalid request body", requestID) return }