fix(api): ensure files array is never null in API response
Add null safety checks to prevent TypeError when backend returns null instead of empty array for files list. Initialize empty slices on backend and add null coalescing on frontend when accessing files state. - Backend: Initialize files slice to always return [] instead of null - Frontend: Add null checks for files state in all map/filter operations
This commit is contained in:
@@ -52,6 +52,11 @@ func (h *Handlers) ListFiles(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Ensure we always encode an array, never null
|
||||
if files == nil {
|
||||
files = []*storage.File{}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(files)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user