do not throw 500 on mojang server error
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
export class UserNotFoundError extends Error {
|
||||
readonly username: string;
|
||||
|
||||
constructor(username: string) {
|
||||
super(`Ein Spieler mit dem Namen '${username}' konnte nicht gefunden werden`);
|
||||
super(`couldn't find a player with the username '${username}'`);
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
||||
export class MojangError 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) {
|
||||
throw response.status < 500
|
||||
? new UserNotFoundError(username)
|
||||
: new Error(`mojang server error (${response.status}): ${await response.text()}`);
|
||||
: new MojangError(`mojang server error (${response.status}): ${await response.text()}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
const id: string = json['id'];
|
||||
|
||||
Reference in New Issue
Block a user