mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-21 18:14:27 +00:00
Address code review feedback - improve data length calculation clarity
- Simplified data length calculation logic in sendFormattedResponse - Simplified data length calculation logic in sendResponseWithOptions - Calculate dataLen after nil conversion for clarity and consistency - All tests still passing Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
@@ -2144,15 +2144,14 @@ func (h *Handler) sendResponse(w common.ResponseWriter, data interface{}, metada
|
|||||||
func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options *ExtendedRequestOptions) {
|
func (h *Handler) sendResponseWithOptions(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options *ExtendedRequestOptions) {
|
||||||
w.SetHeader("Content-Type", "application/json")
|
w.SetHeader("Content-Type", "application/json")
|
||||||
|
|
||||||
// Calculate data length
|
// Handle nil data - convert to empty array
|
||||||
dataLen := 0
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
// When data is nil, return empty array instead of null
|
|
||||||
data = []interface{}{}
|
data = []interface{}{}
|
||||||
} else {
|
|
||||||
dataLen = reflection.Len(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate data length after nil conversion
|
||||||
|
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
|
||||||
if dataLen == 0 {
|
if dataLen == 0 {
|
||||||
w.SetHeader("X-No-Data-Found", "true")
|
w.SetHeader("X-No-Data-Found", "true")
|
||||||
@@ -2210,13 +2209,14 @@ func (h *Handler) normalizeResultArray(data interface{}) interface{} {
|
|||||||
func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options ExtendedRequestOptions) {
|
func (h *Handler) sendFormattedResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata, options ExtendedRequestOptions) {
|
||||||
// Normalize single-record arrays to objects if requested
|
// Normalize single-record arrays to objects if requested
|
||||||
httpStatus := http.StatusOK
|
httpStatus := http.StatusOK
|
||||||
dataLen := 0
|
|
||||||
|
// Handle nil data - convert to empty array
|
||||||
if data == nil {
|
if data == nil {
|
||||||
// When data is nil, return empty array instead of null
|
|
||||||
data = []interface{}{}
|
data = []interface{}{}
|
||||||
} else {
|
|
||||||
dataLen = reflection.Len(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate data length after nil conversion
|
||||||
|
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
|
||||||
if dataLen == 0 {
|
if dataLen == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user