Skip to content

Commit 28f06fa

Browse files
author
Huy Nguyen
committed
Correct error handling for when Recurly returns no records
1 parent 77d9972 commit 28f06fa

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// 200–299 success
4444
if (res.statusCode >= 200 && res.statusCode <= 299) {
4545
if (responsedata === '') {
46-
return _cb(res);
46+
return _cb(res, new Error('Response has no data'));
4747
}
4848
return parser.parseString(responsedata, function (err, result) {
4949
return _cb(res, null, result);
@@ -83,7 +83,7 @@
8383
}
8484
if (callback.length === 2) {
8585
if (err) {
86-
return callback(_wrap_response(res, err));
86+
return callback(err, _wrap_response(res, null));
8787
}
8888
return callback(null, _wrap_response(res, data));
8989

lib/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ exports.makeEachSeriesIterator = function(client, route, endpointName, singleIte
7676
return callback(error);
7777
}
7878

79+
var records = result.data[endpointName][singleItemName];
80+
if (!records) {
81+
return callback(new Error('Response has no data'));
82+
}
83+
7984
var links,
8085
nextQueryString,
8186
nextCursor,
82-
records,
8387
isLimitHit;
8488

8589
// Parse out the next cursor
@@ -91,7 +95,6 @@ exports.makeEachSeriesIterator = function(client, route, endpointName, singleIte
9195
}
9296
}
9397

94-
records = result.data[endpointName][singleItemName];
9598
isLimitHit = limit && (count + records.length) > limit;
9699
if (isLimitHit) {
97100
// We will be over the limit, so slice down

0 commit comments

Comments
 (0)