Skip to content

Commit

Permalink
Ratelimit not saved correctly in case of server error (fixes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreepTheSheep committed Jan 11, 2022
1 parent 6744c01 commit 08ed6c1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/rest/APIRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 08ed6c1

Please sign in to comment.