From b4c4cc2148913c056419a13c8a44c958907f3be2 Mon Sep 17 00:00:00 2001 From: Gabriel Simmer Date: Fri, 5 May 2023 23:51:52 +0100 Subject: [PATCH] Slightly better handling of 404s etc --- api/[domain]/fursona.ts | 3 ++- src/routes/[domain]/+page.svelte | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/[domain]/fursona.ts b/api/[domain]/fursona.ts index 14671c5..aaca240 100644 --- a/api/[domain]/fursona.ts +++ b/api/[domain]/fursona.ts @@ -18,6 +18,7 @@ async function fetcher(url: string) { } } + export default async (request: Request) => { // Proxy the request to the `req.url` value and return it as a JSON string. const params = new URL(request.url).searchParams; @@ -28,7 +29,7 @@ export default async (request: Request) => { } return new Response(JSON.stringify(data), { headers: { - 'content-type': 'application/json' + 'content-type': 'application/json', 'cache-control': 'public, max-age=300, must-revalidate', } }); diff --git a/src/routes/[domain]/+page.svelte b/src/routes/[domain]/+page.svelte index c116775..d2972b1 100644 --- a/src/routes/[domain]/+page.svelte +++ b/src/routes/[domain]/+page.svelte @@ -16,7 +16,13 @@ // Request well-known/fursona file function requestFursona() { fetch(`/api/${$page.params.domain}/fursona`) - .then((res) => res.json()) + .then((res) => { + if (res.ok) { + return res.json(); + } else { + throw new Error(res.statusText); + } + }) .then((data) => { // Cast data to FursonaSchema const sonas_data = data as FursonaSchema; @@ -42,7 +48,7 @@ {:else}
-

Loading...

+

Loading...

{/if}