fix exception when file does not exist
All checks were successful
checks-impure / test (pull_request) Successful in 1m40s
checks / test (pull_request) Successful in 2m55s

fixes #488
This commit is contained in:
Jörg Thalheim 2023-11-14 16:55:01 +01:00
parent 19d7f17310
commit b9618e57c5
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View File

@ -30,6 +30,8 @@ async def root(path_name: str) -> Response:
if not filename.is_file():
log.error("File not found: %s", filename)
return Response(status_code=404)
else:
return Response(status_code=404)
content_type, _ = guess_type(filename)
return Response(filename.read_bytes(), media_type=content_type)

View File

@ -0,0 +1,10 @@
import pytest
from api import TestClient
@pytest.mark.impure
def test_static_files(api: TestClient) -> None:
response = api.get("/")
assert response.headers["content-type"] == "text/html; charset=utf-8"
response = api.get("/does-no-exists.txt")
assert response.status_code == 404