mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-08-31 21:42:36 +00:00
fix(handler): handle JSON marshaling errors in response
Tests / Unit Tests (push) Failing after 4s
Tests / Integration Tests (push) Failing after 23s
Build , Vet Test, and Lint / Build (push) Successful in 52s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 55s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 57s
Build , Vet Test, and Lint / Lint Code (push) Successful in 58s
Tests / Unit Tests (push) Failing after 4s
Tests / Integration Tests (push) Failing after 23s
Build , Vet Test, and Lint / Build (push) Successful in 52s
Build , Vet Test, and Lint / Run Vet Tests (1.24.x) (push) Successful in 55s
Build , Vet Test, and Lint / Run Vet Tests (1.23.x) (push) Successful in 57s
Build , Vet Test, and Lint / Lint Code (push) Successful in 58s
This commit is contained in:
@@ -2902,8 +2902,21 @@ func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{
|
||||
switch options.ResponseFormat {
|
||||
case "simple":
|
||||
// Simple format: just return the data array
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
logger.Error("Failed to marshal JSON response: %v", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if string(jsonData) == "null" {
|
||||
if options.SingleRecordAsObject {
|
||||
jsonData = []byte("{}")
|
||||
} else {
|
||||
jsonData = []byte("[]")
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := w.WriteJSON(data); err != nil {
|
||||
if _, err := w.Write(jsonData); err != nil {
|
||||
logger.Error("Failed to write JSON response: %v", err)
|
||||
}
|
||||
case "syncfusion":
|
||||
|
||||
Reference in New Issue
Block a user