Browse Source

404, not 500

boyska 11 months ago
parent
commit
8b6ede3b2f
1 changed files with 5 additions and 1 deletions
  1. 5 1
      webserver.py

+ 5 - 1
webserver.py

@@ -103,7 +103,11 @@ async def get_all_variables() -> AllVariablesModel:
 
 @app.get("/variables/{key}")
 async def get_variable(key: str) -> VariableModel:
-    return Response(str(settings.variables[key]), media_type='text/plain')
+    try:
+        value = settings.variables[key]
+    except KeyError:
+        raise HTTPException(status_code=404, detail="Variable not found")
+    return Response(str(value), media_type='text/plain')
 
 
 def first_matching(lst: list, condition: Callable[[Any], bool]) -> int: