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,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>