diff --git a/src/rest/APIRequest.js b/src/rest/APIRequest.js index 764d035..bc5ae07 100644 --- a/src/rest/APIRequest.js +++ b/src/rest/APIRequest.js @@ -94,18 +94,20 @@ class APIRequest { * @param {Response} response The response received from the API */ this.client.emit('apiResponse', this, response); - // Save the rate limit details - if (this.url.startsWith(new ReqUtil(this.client).tmioAPIURL)){ - this.client.ratelimit = { - ratelimit: Number(response.headers.raw()['x-ratelimit-limit'][0]), - remaining: Number(response.headers.raw()['x-ratelimit-remaining'][0]), - reset: new Date(Number(response.headers.raw()['x-ratelimit-reset'][0]) * 1000) - }; - } + if (response.status >= 200 && response.status < 300) { + // Save the rate limit details + if (this.url.startsWith(new ReqUtil(this.client).tmioAPIURL)){ + this.client.ratelimit = { + ratelimit: Number(response.headers.raw()['x-ratelimit-limit'][0]), + remaining: Number(response.headers.raw()['x-ratelimit-remaining'][0]), + reset: new Date(Number(response.headers.raw()['x-ratelimit-reset'][0]) * 1000) + }; + } + return await response.json(); } else { - if (response.status == 500) { + if (response.status >= 500) { const json = await response.json(); throw json.error; } else throw response.statusText;