diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-07 10:57:15 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-08-07 10:57:15 +0200 |
commit | db7980504f75371965fe887f2e459c8554ac09d0 (patch) | |
tree | 31c226a63ddefcf67c40b139ba5d612f70e11805 /web/pw-server/src | |
parent | 6f0c1093ac65064c9c19a4137ff897137f74c694 (diff) | |
download | planetwars.dev-db7980504f75371965fe887f2e459c8554ac09d0.tar.xz planetwars.dev-db7980504f75371965fe887f2e459c8554ac09d0.zip |
move match index to ApiClient
Diffstat (limited to 'web/pw-server/src')
-rw-r--r-- | web/pw-server/src/routes/matches/index.svelte | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/web/pw-server/src/routes/matches/index.svelte b/web/pw-server/src/routes/matches/index.svelte index c89013e..af0cd08 100644 --- a/web/pw-server/src/routes/matches/index.svelte +++ b/web/pw-server/src/routes/matches/index.svelte @@ -1,23 +1,22 @@ <script lang="ts" context="module"> - export async function load() { - const res = await fetch("/api/matches", { - headers: { - "Content-Type": "application/json", - }, - }); + import { ApiClient } from "$lib/api_client"; + + export async function load({ fetch }) { + try { + const apiClient = new ApiClient(fetch); + const matches = await apiClient.get("/api/matches"); - if (res.ok) { return { props: { - matches: await res.json(), + matches, }, }; + } catch (error) { + return { + status: error.status, + error: new Error("failed to load matches"), + }; } - - return { - status: res.status, - error: new Error("failed to load matches"), - }; } </script> |