Skip to content

Commit

Permalink
Merge pull request #106 from recurly/pager-bugs
Browse files Browse the repository at this point in the history
Fixing bugs in the Pager
  • Loading branch information
bhelx authored Apr 22, 2020
2 parents 3749301 + a1bfd15 commit adefe7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
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
7 changes: 3 additions & 4 deletions lib/recurly/Pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Pager {
* @return {Number} The count of resources
*/
async count () {
const empty = await this.client._makeRequest('HEAD', this.path, null, { params: this._consumeParams() })
const empty = await this.client._makeRequest('HEAD', this.path, null, { params: this.params })
return empty.getResponse().recordCount
}

Expand All @@ -49,9 +49,8 @@ class Pager {
* @return {Object} The first resource in the list
*/
async first () {
this.params = this.params || {}
this.params['limit'] = 1
let results = await this.client._makeRequest('GET', this.path, null, { params: this._consumeParams() })
const firstParams = Object.assign({}, this.params, { limit: 1 })
let results = await this.client._makeRequest('GET', this.path, null, { params: firstParams })
return results.data && results.data[0]
}

Expand Down

0 comments on commit adefe7e

Please sign in to comment.