From c0114401c8e316c619f4a2cca10bda6c066a010a Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:54:38 -0500 Subject: [PATCH] [O] Don't 200 error --- server/host.py | 4 ++-- src/Launcher.svelte | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/host.py b/server/host.py index ee45b63..7651264 100644 --- a/server/host.py +++ b/server/host.py @@ -3,7 +3,7 @@ import random from fastapi.responses import RedirectResponse import uvicorn from subprocess import check_output -from fastapi import FastAPI, Request +from fastapi import FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from pathlib import Path @@ -61,7 +61,7 @@ async def input_request(request: Request): async def get_puzzle(id: str): tf = data / f"{id}.json" if not tf.exists(): - return {"error": "Puzzle not found"} + raise HTTPException(status_code=404, detail="Puzzle not found") return json.loads(tf.read_text()) diff --git a/src/Launcher.svelte b/src/Launcher.svelte index 481ab00..fd709fd 100644 --- a/src/Launcher.svelte +++ b/src/Launcher.svelte @@ -6,9 +6,10 @@ const urlParams = new URLSearchParams(window.location.search); const puzzleId = urlParams.get("puzzle"); let puzzleData: Checkpoint | null = null; + let error: string | null = null; if (!puzzleId) window.location.href = "/?puzzle=meow"; - else Backend.get(puzzleId).then((data) => (puzzleData = data)); + else Backend.get(puzzleId).then((data) => (puzzleData = data)).catch((e) => (error = e)); {#if puzzleData !== null && puzzleId !== null} @@ -18,8 +19,12 @@