Skip to content

Commit

Permalink
fix: handle nil pagination responses when HTTP status is 200 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Jul 31, 2024
1 parent 06f83cf commit cf14c8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions hrisdirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func (r *IndividualsPage) GetNextPage() (res *IndividualsPage, err error) {
}

func (r *IndividualsPage) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
if r == nil {
r = &IndividualsPage{}
}
r.cfg = cfg
r.res = res
}
Expand Down
9 changes: 9 additions & 0 deletions internal/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (r *SinglePage[T]) GetNextPage() (res *SinglePage[T], err error) {
}

func (r *SinglePage[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
if r == nil {
r = &SinglePage[T]{}
}
r.cfg = cfg
r.res = res
}
Expand Down Expand Up @@ -146,6 +149,9 @@ func (r *ResponsesPage[T]) GetNextPage() (res *ResponsesPage[T], err error) {
}

func (r *ResponsesPage[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
if r == nil {
r = &ResponsesPage[T]{}
}
r.cfg = cfg
r.res = res
}
Expand Down Expand Up @@ -240,6 +246,9 @@ func (r *Page[T]) GetNextPage() (res *Page[T], err error) {
}

func (r *Page[T]) SetPageConfig(cfg *requestconfig.RequestConfig, res *http.Response) {
if r == nil {
r = &Page[T]{}
}
r.cfg = cfg
r.res = res
}
Expand Down
2 changes: 1 addition & 1 deletion internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (cfg *RequestConfig) Execute() (err error) {

err = json.NewDecoder(bytes.NewReader(contents)).Decode(cfg.ResponseBodyInto)
if err != nil {
err = fmt.Errorf("error parsing response json: %w", err)
return fmt.Errorf("error parsing response json: %w", err)
}

return nil
Expand Down

0 comments on commit cf14c8d

Please sign in to comment.