diff --git a/src/components/Table.vue b/src/components/Table.vue index 7cac8c2..66bcb33 100644 --- a/src/components/Table.vue +++ b/src/components/Table.vue @@ -5,7 +5,7 @@

Cartes

-
+
{{card}}
@@ -14,7 +14,7 @@

Cartes TriƩes

Shape order : {{sortResult.shapeOrder}}

Number order : {{sortResult.numberOrder}}

-
+
{{card}}
@@ -36,12 +36,17 @@ export default { methods: { initHand() { this.sortResult = null; - getHand().then(r => { + this.cards = null; + getHand().catch(() => { + window.alert("Deck not full enough") + }).then(r => { this.cards = r; }) }, sortMyHand() { - sortHand(this.cards).then(r => { + sortHand(this.cards).catch(() => { + window.alert("Can't sort cards") + }).then(r => { this.sortResult = r; }); }, diff --git a/src/services/DeckService.js b/src/services/DeckService.js index e4486c1..d5b94c6 100644 --- a/src/services/DeckService.js +++ b/src/services/DeckService.js @@ -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; }