Skip to content

Commit

Permalink
json API: return empty array instead of "no rows" error
Browse files Browse the repository at this point in the history
Hopefully, this fixes the problem seen in #62 where tables never seemed to finish loading because the request returned JSON saying "null".
  • Loading branch information
bsiegert committed Aug 22, 2024
1 parent 1aa85a8 commit 6b71b62
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

result, err := a.dispatch(ctx, paths[0], paths[1:], r.Form)
if err == sql.ErrNoRows {
// If there were no results, return an empty array instead of null.
io.WriteString(w, "[]")
return
}
if err != nil {
if result != nil {
json.NewEncoder(w).Encode(result)
Expand Down

0 comments on commit 6b71b62

Please sign in to comment.