[+] Failure

This commit is contained in:
2024-12-17 00:58:30 -05:00
parent c0114401c8
commit df23f9f878
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -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));
</script>
{#if puzzleData !== null && puzzleId !== null}
+4 -1
View File
@@ -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) }),
}