[O] Don't 200 error

This commit is contained in:
2024-12-17 00:54:38 -05:00
parent 3d48caada0
commit c0114401c8
2 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -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())
+7 -2
View File
@@ -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));
</script>
{#if puzzleData !== null && puzzleId !== null}
@@ -18,8 +19,12 @@
<div>
{#if puzzleId === null}
<a href="/?puzzle=meow">Redirecting...</a>
{:else if error}
<h2 class="error">Error</h2>
<span>{error}</span>
{:else}
<div>Loading...</div>
<h2>Loading...</h2>
<span>Fetching puzzle data...</span>
{/if}
</div>
</div>