mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-05-21 03:25:21 +00:00
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
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
This commit is contained in:
@@ -2561,10 +2561,8 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
|
||||
dataLen := reflection.Len(data)
|
||||
|
||||
// Add X-No-Data-Found header when no records were found
|
||||
httpStatus := http.StatusOK
|
||||
if dataLen == 0 {
|
||||
w.SetHeader("X-No-Data-Found", "true")
|
||||
httpStatus = http.StatusNoContent
|
||||
}
|
||||
|
||||
// Apply normalization after header is set
|
||||
@@ -2588,7 +2586,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
|
||||
switch options.ResponseFormat {
|
||||
case "simple":
|
||||
// Simple format: just return the data array
|
||||
w.WriteHeader(httpStatus)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := w.WriteJSON(data); err != nil {
|
||||
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 {
|
||||
response["count"] = metadata.Total
|
||||
}
|
||||
w.WriteHeader(httpStatus)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := w.WriteJSON(response); err != nil {
|
||||
logger.Error("Failed to write JSON response: %v", err)
|
||||
}
|
||||
@@ -2611,7 +2609,7 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
|
||||
Data: data,
|
||||
Metadata: metadata,
|
||||
}
|
||||
w.WriteHeader(httpStatus)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := w.WriteJSON(response); err != nil {
|
||||
logger.Error("Failed to write JSON response: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user