From c71e09a4017823d0c3c486086d7855541be45b77 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 16 Apr 2021 13:21:56 -0500 Subject: Update hypixelApi.js --- build/hypixelApi.js | 7 +++++-- 1 file 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; } -- cgit