aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-03-02 10:27:47 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-03-02 10:27:47 -0600
commitee0ce21292dc53d11b5d6613465c502b0bb7a34a (patch)
tree0e7d7f7bcfa2d7b752b754624e1b591aaa229841
parent2c2a465efb2535f2d9ce8d5865c276e2e91c4979 (diff)
downloadskyblock-api-ee0ce21292dc53d11b5d6613465c502b0bb7a34a.tar.gz
skyblock-api-ee0ce21292dc53d11b5d6613465c502b0bb7a34a.tar.bz2
skyblock-api-ee0ce21292dc53d11b5d6613465c502b0bb7a34a.zip
fix some errors with invalid players
-rw-r--r--src/hypixelCached.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index 483b3fa..0d5e0e3 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -78,6 +78,10 @@ export async function uuidFromUser(user: string): Promise<string> {
if (usernameCache.has(undashUuid(user))) {
// check if the uuid is a key
const username: any = usernameCache.get(undashUuid(user))
+
+ // sometimes the username will be null, return that
+ if (username === null) return username
+
// if it has .then, then that means its a waitForCacheSet promise. This is done to prevent requests made while it is already requesting
if (username.then) {
const { key: uuid, value: _username } = await username
@@ -209,6 +213,9 @@ export async function fetchSkyblockProfiles(playerUuid: string): Promise<CleanPr
/** Fetch an array of `BasicProfile`s */
async function fetchBasicProfiles(user: string): Promise<CleanBasicProfile[]> {
const playerUuid = await uuidFromUser(user)
+
+ if (!playerUuid) return // invalid player, just return
+
if (basicProfilesCache.has(playerUuid)) {
if (debug) console.log('Cache hit! fetchBasicProfiles', playerUuid)
return basicProfilesCache.get(playerUuid)
@@ -242,6 +249,7 @@ export async function fetchProfileUuid(user: string, profile: string) {
if (debug) console.log('Cache miss: fetchProfileUuid', user)
const profiles = await fetchBasicProfiles(user)
+ if (!profiles) return // user probably doesnt exist
const profileUuid = undashUuid(profile)