fix(pagination): check if page data is empty in GetNextPage

This commit is contained in:
stainless-app[bot]
2025-06-27 01:14:01 +00:00
parent b10d28d1e2
commit 36cedbb1e5

View File

@@ -43,6 +43,9 @@ func (r *Page[T]) UnmarshalJSON(data []byte) error {
// there is no next page, this function will return a 'nil' for the page value, but
// will not return an error
func (r *Page[T]) GetNextPage() (res *Page[T], err error) {
if len(r.Data) == 0 {
return nil, nil
}
// This page represents a response that isn't actually paginated at the API level
// so there will never be a next page.
cfg := (*requestconfig.RequestConfig)(nil)
@@ -137,6 +140,10 @@ func (r *CursorPage[T]) UnmarshalJSON(data []byte) error {
// there is no next page, this function will return a 'nil' for the page value, but
// will not return an error
func (r *CursorPage[T]) GetNextPage() (res *CursorPage[T], err error) {
if len(r.Data) == 0 {
return nil, nil
}
if r.JSON.HasMore.Valid() && r.HasMore == false {
return nil, nil
}