From df23f9f878831526de7a59fb8589fef53df3a6c2 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:58:30 -0500 Subject: [PATCH] [+] Failure --- src/Launcher.svelte | 2 +- src/utils.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Launcher.svelte b/src/Launcher.svelte index fd709fd..a295256 100644 --- a/src/Launcher.svelte +++ b/src/Launcher.svelte @@ -9,7 +9,7 @@ let error: string | null = null; if (!puzzleId) window.location.href = "/?puzzle=meow"; - else Backend.get(puzzleId).then((data) => (puzzleData = data)).catch((e) => (error = e)); + else Backend.get(puzzleId).then((data) => (puzzleData = data)).catch(e => (error = e)); {#if puzzleData !== null && puzzleId !== null} diff --git a/src/utils.ts b/src/utils.ts index 86043fb..15cee76 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -71,6 +71,9 @@ export const Fmt = { } export const Backend = { - get: (id: string) => fetch(`${cfg.backend}/${id}`).then(r => r.text()).then(JsonTy.parse), + get: (id: string) => fetch(`${cfg.backend}/${id}`).then(r => { + if (!r.ok) throw new Error(`Failed to get puzzle: ${r.status}`) + r.text() + }).then(JsonTy.parse), post: (data: Checkpoint) => fetch(`${cfg.backend}/`, { method: "post", body: JsonTy.stringify(data) }), }