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 <noreply@anthropic.com>
This commit is contained in:
shankar0123
2026-03-23 17:39:16 -04:00
parent 43a03c168c
commit b227502cef
+3 -2
View File
@@ -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
}