From 5bdfae709d80c61039222a6491634f0b5e011996 Mon Sep 17 00:00:00 2001 From: Doug Miller Date: Tue, 21 Apr 2020 15:27:48 -0500 Subject: [PATCH] Fixing bugs in the Pager --- lib/recurly/BaseClient.js | 2 +- lib/recurly/Pager.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/recurly/BaseClient.js b/lib/recurly/BaseClient.js index 477ed2ce..0dcd883c 100644 --- a/lib/recurly/BaseClient.js +++ b/lib/recurly/BaseClient.js @@ -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 diff --git a/lib/recurly/Pager.js b/lib/recurly/Pager.js index b49cb250..160138df 100644 --- a/lib/recurly/Pager.js +++ b/lib/recurly/Pager.js @@ -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 } @@ -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] }