Skip to content

Commit

Permalink
Fixing bugs in the Pager
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmiller committed Apr 21, 2020
1 parent 97e2656 commit 5bdfae7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/recurly/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class BaseClient {
const jsonContent = (resp.contentType && resp.contentType.includes(JSON_CONTENT_TYPE))

if (resp.status < 200 || resp.status > 299) {
if (jsonContent) {
if (jsonContent && resp.body) {
const errBody = resp.body && JSON.parse(resp.body).error
// If we have a body, we determine the error based on
// the contents of the body
Expand Down
6 changes: 6 additions & 0 deletions lib/recurly/Pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Pager {
*/
async count () {
const empty = await this.client._makeRequest('HEAD', this.path, null, { params: this._consumeParams() })
// Reset this value to false so that the actual paging attempt
// will include params in the initial request.
this._paramsConsumed = false
return empty.getResponse().recordCount
}

Expand All @@ -52,6 +55,9 @@ class Pager {
this.params = this.params || {}
this.params['limit'] = 1
let results = await this.client._makeRequest('GET', this.path, null, { params: this._consumeParams() })
// Reset this value to false so that the actual paging attempt
// will include params in the initial request.
this._paramsConsumed = false
return results.data && results.data[0]
}

Expand Down

0 comments on commit 5bdfae7

Please sign in to comment.