From b5ce577cb9dd2b29b3c92bc8112ee8e2704d86cd Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 10 Sep 2019 22:35:42 +0100 Subject: [PATCH] fix: rate limit detection (#108) `body` is not null. In my experience I got: ```json body: '{"data":{"rateLimit":{"cost":1,"remaining":0,"resetAt":"2019-08-05T12:01:30Z"},"node":{"comments":{"pageInfo":{"endCursor"... ``` I'm not certain why it would need to be `null` and why inspection of the header wouldn't suffice. `statusCode` check is also unnecessary, `queryRequest` rejects for non-200 responses so `rateLimited` will not be called in this case. --- src/graphql.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/graphql.js b/src/graphql.js index 84d9fdf..0b24630 100644 --- a/src/graphql.js +++ b/src/graphql.js @@ -420,9 +420,8 @@ const abusive = e => { } const rateLimited = e => { - const body = JSON.parse(e.body) const rem = e && e.headers && e.headers['x-ratelimit-remaining'] - return e.status === 200 && body.data === null && rem && parseInt(rem) === 0 + return rem && parseInt(rem) === 0 } const untilReset = e => {