skip java uuid request/validation if api sends rate limit response
All checks were successful
delpoy / build-and-deploy (push) Successful in 51s

This commit is contained in:
2024-12-01 15:46:41 +01:00
parent 5e07f4d545
commit abffa440a1
3 changed files with 19 additions and 2 deletions

View File

@@ -9,11 +9,16 @@ export class UserNotFoundError extends Error {
}
}
export class RateLimitError extends Error {}
export class ApiError extends Error {}
export async function getJavaUuid(username: string): Promise<string> {
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
if (!response.ok) {
if (response.status == 429) {
throw new RateLimitError();
}
throw response.status < 500
? new UserNotFoundError(username)
: new ApiError(`mojang server error (${response.status}): ${await response.text()}`);