move match index to ApiClient

This commit is contained in:
Ilion Beyst 2022-08-07 10:57:15 +02:00
parent 6f0c1093ac
commit db7980504f

View file

@ -1,24 +1,23 @@
<script lang="ts" context="module"> <script lang="ts" context="module">
export async function load() { import { ApiClient } from "$lib/api_client";
const res = await fetch("/api/matches", {
headers: { export async function load({ fetch }) {
"Content-Type": "application/json", try {
}, const apiClient = new ApiClient(fetch);
}); const matches = await apiClient.get("/api/matches");
if (res.ok) {
return { return {
props: { props: {
matches: await res.json(), matches,
}, },
}; };
} } catch (error) {
return { return {
status: res.status, status: error.status,
error: new Error("failed to load matches"), error: new Error("failed to load matches"),
}; };
} }
}
</script> </script>
<script lang="ts"> <script lang="ts">