diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-16 13:21:56 -0500 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-16 13:21:56 -0500 |
commit | c71e09a4017823d0c3c486086d7855541be45b77 (patch) | |
tree | 6bd0d24865d77a8dc9a4e0721700fabac18cac3d | |
parent | a7376adb681bd6821f9af6fc6e56f734fcc5c2e7 (diff) | |
download | skyblock-api-c71e09a4017823d0c3c486086d7855541be45b77.tar.gz skyblock-api-c71e09a4017823d0c3c486086d7855541be45b77.tar.bz2 skyblock-api-c71e09a4017823d0c3c486086d7855541be45b77.zip |
Update hypixelApi.js
-rw-r--r-- | build/hypixelApi.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/build/hypixelApi.js b/build/hypixelApi.js index 2b3a601..e4ba7ff 100644 --- a/build/hypixelApi.js +++ b/build/hypixelApi.js @@ -52,8 +52,10 @@ async function sendApiRequest({ path, key, args }) { // Construct a url from the base api url, path, and arguments const fetchUrl = baseHypixelAPI + '/' + path + '?' + util_1.jsonToQuery(args); let fetchResponse; + let fetchJsonParsed; try { fetchResponse = await node_fetch_1.default(fetchUrl, { agent: () => httpsAgent }); + fetchJsonParsed = await fetchResponse.json(); } catch { // if there's an error, wait a second and try again @@ -67,11 +69,12 @@ async function sendApiRequest({ path, key, args }) { limit: fetchResponse.headers['ratelimit-limit'], reset: Date.now() + parseInt(fetchResponse.headers['ratelimit-reset']) * 1000 }; - const fetchJsonParsed = await fetchResponse.json(); if (fetchJsonParsed.throttle) { if (apiKeyUsage[key]) apiKeyUsage[key].remaining = 0; - return { throttled: true }; + // if it's throttled, wait 10 seconds and try again + await new Promise((resolve) => setTimeout(resolve, 10000)); + return await sendApiRequest({ path, key, args }); } return fetchJsonParsed; } |