diff options
-rw-r--r-- | build/mojang.js | 12 | ||||
-rw-r--r-- | src/mojang.ts | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/build/mojang.js b/build/mojang.js index b740c5a..5216d39 100644 --- a/build/mojang.js +++ b/build/mojang.js @@ -29,14 +29,24 @@ async function profileFromUuid(uuid) { await new Promise((resolve) => setTimeout(resolve, 1000)); return await profileFromUuid(uuid); } + let dataString; + try { + dataString = await fetchResponse.text(); + } + catch { + return { uuid: null, username: null }; + } let data; try { - data = await fetchResponse.json(); + data = JSON.parse(dataString); } catch { + console.log('mojang response:', dataString); // if it errors, just return null return { uuid: null, username: null }; } + if (!data.id) + console.log('mojang response:', data); return { uuid: data.id, username: data.name diff --git a/src/mojang.ts b/src/mojang.ts index dd5c6bb..f73fe99 100644 --- a/src/mojang.ts +++ b/src/mojang.ts @@ -37,13 +37,22 @@ export async function profileFromUuid(uuid: string): Promise<MojangApiResponse> return await profileFromUuid(uuid) } + let dataString: string + try { + dataString = await fetchResponse.text() + } catch { + return { uuid: null, username: null } + } let data try { - data = await fetchResponse.json() + data = JSON.parse(dataString) } catch { + console.log('mojang response:', dataString) // if it errors, just return null return { uuid: null, username: null } } + if (!data.id) + console.log('mojang response:', data) return { uuid: data.id, username: data.name |