improved fetch in gameServer

This commit is contained in:
LuckyLaszlo
2023-01-15 02:00:42 +01:00
parent 4318b8a707
commit a2b2168884
3 changed files with 60 additions and 29 deletions

View File

@@ -4,7 +4,7 @@ export async function fetchAvatar(username: string)
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar?username=${username}`)
.then((response) => {
if (!response.ok) {
throw new Error("Avatar not retrieved");
throw new Error("HTTP " + response.status);
}
return response.blob();
})
@@ -22,7 +22,7 @@ export async function fetchUser()
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
.then((response) => {
if (!response.ok) {
throw new Error("User not retrieved");
throw new Error("HTTP " + response.status);
}
return response.json();
})
@@ -40,7 +40,7 @@ export async function fetchAllUsers()
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
.then((response) => {
if (!response.ok) {
throw new Error("All Users not retrieved");
throw new Error("HTTP " + response.status);
}
return response.json();
})