From 03991ab4890202dcfd5415da66773638245dccf1 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 30 Jun 2021 01:15:19 -0500 Subject: fix error that happens sometimes for nonexistent players --- build/cleaners/skyblock/profile.js | 2 ++ build/cleaners/skyblock/profiles.js | 2 +- src/cleaners/skyblock/profile.ts | 4 ++-- src/cleaners/skyblock/profiles.ts | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/build/cleaners/skyblock/profile.js b/build/cleaners/skyblock/profile.js index da988cc..6460c3b 100644 --- a/build/cleaners/skyblock/profile.js +++ b/build/cleaners/skyblock/profile.js @@ -48,6 +48,8 @@ exports.cleanSkyblockProfileResponseLighter = cleanSkyblockProfileResponseLighte async function cleanSkyblockProfileResponse(data, options) { // We use Promise.all so it can fetch all the users at once instead of waiting for the previous promise to complete const promises = []; + if (!data) + return null; for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID]; memberRaw.uuid = memberUUID; diff --git a/build/cleaners/skyblock/profiles.js b/build/cleaners/skyblock/profiles.js index ba84303..b916209 100644 --- a/build/cleaners/skyblock/profiles.js +++ b/build/cleaners/skyblock/profiles.js @@ -20,7 +20,7 @@ async function cleanSkyblockProfilesResponse(data) { // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) promises.push(profile_1.cleanSkyblockProfileResponse(profile)); } - const cleanedProfiles = await Promise.all(promises); + const cleanedProfiles = (await Promise.all(promises)).filter(p => p); return cleanedProfiles; } exports.cleanSkyblockProfilesResponse = cleanSkyblockProfilesResponse; diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index 5bcea4b..e4d2a94 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -46,10 +46,10 @@ export async function cleanSkyblockProfileResponseLighter(data): Promise { +export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptions): Promise { // We use Promise.all so it can fetch all the users at once instead of waiting for the previous promise to complete const promises: Promise[] = [] - + if (!data) return null for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID] memberRaw.uuid = memberUUID diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts index a44fe48..a068dae 100644 --- a/src/cleaners/skyblock/profiles.ts +++ b/src/cleaners/skyblock/profiles.ts @@ -19,11 +19,11 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl /** Convert an array of raw profiles into clean profiles */ export async function cleanSkyblockProfilesResponse(data: any[]): Promise { - const promises: Promise[] = [] + const promises: Promise[] = [] for (const profile of data ?? []) { // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) promises.push(cleanSkyblockProfileResponse(profile)) } - const cleanedProfiles: CleanProfile[] = await Promise.all(promises) + const cleanedProfiles: CleanProfile[] = (await Promise.all(promises)).filter(p => p) as CleanProfile[] return cleanedProfiles } -- cgit