mirror of
https://github.com/openai/openai-go.git
synced 2026-03-31 16:47:11 +09:00
fix(pagination): check if page data is empty in GetNextPage
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user