[O] Don't 200 error
This commit is contained in:
+2
-2
@@ -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
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user