diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-04-13 16:30:27 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 16:30:27 -0500 |
commit | ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f (patch) | |
tree | 600846dd4804c487d16d33dd99ad4073d815e8f3 /src/hypixelApi.ts | |
parent | c0d03a8d0c1e75967f48cb27d9c55bc4707af22c (diff) | |
download | skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.gz skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.tar.bz2 skyblock-api-ac79dfbc6ad6eb56bc814471d49b95f014d3eb5f.zip |
Slayer leaderboard (#4)
* add slayers to constants
* Compiled TS into JS
* change units to also show up when only changing one constant item
* Compiled TS into JS
* add slayer leaderboards
* remove debugging stuff
Diffstat (limited to 'src/hypixelApi.ts')
-rw-r--r-- | src/hypixelApi.ts | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts index 5c4bb2b..8541089 100644 --- a/src/hypixelApi.ts +++ b/src/hypixelApi.ts @@ -2,6 +2,7 @@ * Fetch the raw Hypixel API */ import fetch from 'node-fetch' +import * as nodeFetch from 'node-fetch' import { jsonToQuery, shuffle } from './util' import { Agent } from 'https' @@ -136,10 +137,18 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon // Construct a url from the base api url, path, and arguments const fetchUrl = baseHypixelAPI + '/' + path + '?' + jsonToQuery(args) - const fetchResponse = await fetch( - fetchUrl, - { agent: () => httpsAgent } - ) + let fetchResponse: nodeFetch.Response + + try { + fetchResponse = await fetch( + fetchUrl, + { agent: () => httpsAgent } + ) + } catch { + // if there's an error, wait a second and try again + await new Promise((resolve) => setTimeout(resolve, 1000)) + return await sendApiRequest({ path, key, args }) + } if (fetchResponse.headers['ratelimit-limit']) // remember how many uses it has |