diff options
author | mat <github@matdoes.dev> | 2022-04-10 12:20:25 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-04-10 12:20:25 -0500 |
commit | 8435e97486dcddf45f0aa11abdab4a3dd047ffc2 (patch) | |
tree | ef24054bf2f0e9dfbba65badb6149078b5a06ad1 /src | |
parent | 772e3d415e52d7d020cdddfb061df3f433049f7c (diff) | |
download | skyblock-api-8435e97486dcddf45f0aa11abdab4a3dd047ffc2.tar.gz skyblock-api-8435e97486dcddf45f0aa11abdab4a3dd047ffc2.tar.bz2 skyblock-api-8435e97486dcddf45f0aa11abdab4a3dd047ffc2.zip |
fix y200 century cake & throw error earlier when hypixel api returns null
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/claimed.ts | 2 | ||||
-rw-r--r-- | src/database.ts | 4 | ||||
-rw-r--r-- | src/hypixel.ts | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/src/cleaners/skyblock/claimed.ts b/src/cleaners/skyblock/claimed.ts index f30dedf..0873af9 100644 --- a/src/cleaners/skyblock/claimed.ts +++ b/src/cleaners/skyblock/claimed.ts @@ -18,7 +18,7 @@ export function cleanPlayerSkyblockClaimed(data: typedHypixelApi.PlayerDataRespo const centuryCakes = Object.keys(data).filter((key) => key.startsWith('claimed_century_cake')) for (const centuryCake of centuryCakes) { - const centuryCakeYear = centuryCake === 'claimed_century_cake' ? '100' : centuryCakes.slice('claimed_century_cake'.length) + const centuryCakeYear = centuryCake === 'claimed_century_cake' ? '100' : centuryCake.slice('claimed_century_cake'.length) claimedItems.push({ name: `year_${centuryCakeYear}_century_cake`, timestamp: data[centuryCake] diff --git a/src/database.ts b/src/database.ts index fa4cbd2..9e29328 100644 --- a/src/database.ts +++ b/src/database.ts @@ -934,7 +934,7 @@ async function removeBadMemberLeaderboardAttributes(): Promise<void> { export let finishedCachingRawLeaderboards = false /** Fetch all the leaderboards, used for caching. Don't call this often! */ -async function fetchAllLeaderboards(fast?: boolean): Promise<void> { +async function fetchAllLeaderboards(): Promise<void> { const leaderboards: string[] = await fetchAllMemberLeaderboardAttributes() if (debug) console.debug('Caching raw leaderboards!') @@ -1006,7 +1006,7 @@ if (!globalThis.isTest) { // when it connects, cache the leaderboards and remove bad members removeBadMemberLeaderboardAttributes() // cache leaderboards on startup so its faster later on - fetchAllLeaderboards(true) + fetchAllLeaderboards() // cache leaderboard players again every 4 hours setInterval(fetchAllLeaderboards, 4 * 60 * 60 * 1000) }) diff --git a/src/hypixel.ts b/src/hypixel.ts index 549f593..d01e699 100644 --- a/src/hypixel.ts +++ b/src/hypixel.ts @@ -50,6 +50,8 @@ export interface ApiOptions { export async function sendCleanApiRequest<P extends keyof typeof cleanResponseFunctions>(path: P, args: Omit<typedHypixelApi.Requests[P]['options'], 'key'>, options?: ApiOptions): Promise<Awaited<ReturnType<typeof cleanResponseFunctions[P]>>> { const key = await chooseApiKey() const data = await sendApiRequest(path, { key, ...args }) + if (!data) + throw new Error(`No data returned from ${path}`) // clean the response return await cleanResponse(path, data, options ?? {}) } |