Compare commits

...

1 Commits

Author SHA1 Message Date
Hein
3d2e11eeed fix(restheadspec): always respond 200 OK regardless of result count in sendFormattedResponse
Some checks failed
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in -33m27s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in -32m51s
Build , Vet Test, and Lint / Lint Code (push) Failing after -33m3s
Build , Vet Test, and Lint / Build (push) Successful in -33m10s
Tests / Unit Tests (push) Successful in -33m58s
Tests / Integration Tests (push) Failing after -34m20s
2026-05-19 09:46:25 +02:00

View File

@@ -2561,10 +2561,8 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
dataLen := reflection.Len(data) dataLen := reflection.Len(data)
// Add X-No-Data-Found header when no records were found // Add X-No-Data-Found header when no records were found
httpStatus := http.StatusOK
if dataLen == 0 { if dataLen == 0 {
w.SetHeader("X-No-Data-Found", "true") w.SetHeader("X-No-Data-Found", "true")
httpStatus = http.StatusNoContent
} }
// Apply normalization after header is set // Apply normalization after header is set
@@ -2588,7 +2586,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
switch options.ResponseFormat { switch options.ResponseFormat {
case "simple": case "simple":
// Simple format: just return the data array // Simple format: just return the data array
w.WriteHeader(httpStatus) w.WriteHeader(http.StatusOK)
if err := w.WriteJSON(data); err != nil { if err := w.WriteJSON(data); err != nil {
logger.Error("Failed to write JSON response: %v", err) logger.Error("Failed to write JSON response: %v", err)
} }
@@ -2600,7 +2598,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
if metadata != nil { if metadata != nil {
response["count"] = metadata.Total response["count"] = metadata.Total
} }
w.WriteHeader(httpStatus) w.WriteHeader(http.StatusOK)
if err := w.WriteJSON(response); err != nil { if err := w.WriteJSON(response); err != nil {
logger.Error("Failed to write JSON response: %v", err) logger.Error("Failed to write JSON response: %v", err)
} }
@@ -2611,7 +2609,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
Data: data, Data: data,
Metadata: metadata, Metadata: metadata,
} }
w.WriteHeader(httpStatus) w.WriteHeader(http.StatusOK)
if err := w.WriteJSON(response); err != nil { if err := w.WriteJSON(response); err != nil {
logger.Error("Failed to write JSON response: %v", err) logger.Error("Failed to write JSON response: %v", err)
} }