浏览代码

Add exception for unknown ontologies

Arkadiusz Ryś 2 年之前
父节点
当前提交
171290c484
共有 1 个文件被更改,包括 3 次插入1 次删除
  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"