fix pagination issues on backend

This commit is contained in:
Hayden 2022-12-31 11:43:55 -09:00
parent 188bd054e5
commit c379a73a63
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 17 additions and 10 deletions

View file

@ -1,6 +1,8 @@
package v1
import (
"database/sql"
"errors"
"net/http"
"github.com/hay-kot/homebox/backend/internal/core/services"
@ -41,6 +43,11 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
ctx := services.NewContext(r.Context())
items, err := ctrl.repo.Items.QueryByGroup(ctx, ctx.GID, extractQuery(r))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return server.Respond(w, http.StatusOK, repo.PaginationResult[repo.ItemSummary]{
Items: []repo.ItemSummary{},
})
}
log.Err(err).Msg("failed to get items")
return validate.NewRequestError(err, http.StatusInternalServerError)
}