From 36cedbb1e506e76b404afe5bb8d30ea04e92c485 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 27 Jun 2025 01:14:01 +0000 Subject: [PATCH] fix(pagination): check if page data is empty in GetNextPage --- packages/pagination/pagination.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/pagination/pagination.go b/packages/pagination/pagination.go index db382e3..528cda8 100644 --- a/packages/pagination/pagination.go +++ b/packages/pagination/pagination.go @@ -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 }