Explorar o código

Add exception for unknown ontologies

Arkadiusz Ryś %!s(int64=2) %!d(string=hai) anos
pai
achega
171290c484
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      ontopoint/main.py

+ 3 - 1
ontopoint/main.py

@@ -1,6 +1,6 @@
 from pathlib import Path
 # import magic
-from fastapi import FastAPI, BackgroundTasks
+from fastapi import FastAPI, BackgroundTasks, HTTPException
 from starlette.responses import FileResponse
 # http://127.0.0.1:8000/
 # http://127.0.0.1:8000/docs
@@ -25,6 +25,8 @@ async def root():
 @app.get("/{name}")
 async def ontology(name: str, background_tasks: BackgroundTasks):
     file_path = data_path / Path(name)
+    if not file_path.exists():
+        raise HTTPException(status_code=404, detail=f"Ontology {name} not found!")
     # mime = magic.Magic(mime=True)
     # media_type = mime.from_file(file_path)
     media_type = "text/xml"