diff options
Diffstat (limited to 'web/pw-server/src/routes')
-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> |