Error handeling.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user