Skip to content

Commit 36cedbb

Browse files
fix(pagination): check if page data is empty in GetNextPage
1 parent b10d28d commit 36cedbb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/pagination/pagination.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func (r *Page[T]) UnmarshalJSON(data []byte) error {
4343
// there is no next page, this function will return a 'nil' for the page value, but
4444
// will not return an error
4545
func (r *Page[T]) GetNextPage() (res *Page[T], err error) {
46+
if len(r.Data) == 0 {
47+
return nil, nil
48+
}
4649
// This page represents a response that isn't actually paginated at the API level
4750
// so there will never be a next page.
4851
cfg := (*requestconfig.RequestConfig)(nil)
@@ -137,6 +140,10 @@ func (r *CursorPage[T]) UnmarshalJSON(data []byte) error {
137140
// there is no next page, this function will return a 'nil' for the page value, but
138141
// will not return an error
139142
func (r *CursorPage[T]) GetNextPage() (res *CursorPage[T], err error) {
143+
if len(r.Data) == 0 {
144+
return nil, nil
145+
}
146+
140147
if r.JSON.HasMore.Valid() && r.HasMore == false {
141148
return nil, nil
142149
}

0 commit comments

Comments
 (0)