Error handeling.

This commit is contained in:
aminecmi
2021-10-30 16:45:47 +02:00
parent 2bfcc80f0e
commit a47d382e71
2 changed files with 20 additions and 8 deletions
+11 -4
View File
@@ -1,6 +1,10 @@
export async function getHand() {
const response = await fetch('http://localhost:8080/api/deck/hand');
return await response.json();
if (response.status >= 200 && response.status <= 299) {
return await response.json();
} else {
throw Error(response.statusText);
}
}
export async function sortHand(hand) {
@@ -9,12 +13,15 @@ export async function sortHand(hand) {
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(hand)
})
return await response.json();
if (response.status >= 200 && response.status <= 299) {
return await response.json();
} else {
throw Error(response.statusText);
}
}
export async function resetDeck() {
const response = await fetch(`http://localhost:8080/api/deck:reset`, {
return await fetch(`http://localhost:8080/api/deck:reset`, {
method: 'PUT'
})
await response;
}