Skip to content

Commit

Permalink
Merge pull request #126 from davidbrochart/fix_get_content
Browse files Browse the repository at this point in the history
Return 404 when content not found
  • Loading branch information
davidbrochart authored Dec 1, 2021
2 parents 4876875 + 1814b5f commit e732e30
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/contents/fps_contents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Content(BaseModel):
name: str
path: str
last_modified: Optional[str]
created: str
created: Optional[str]
content: Optional[Union[str, List[Dict]]]
format: Optional[str]
mimetype: Optional[str]
Expand Down
9 changes: 5 additions & 4 deletions plugins/contents/fps_contents/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Dict, List, Optional, Union, cast

from fps.hooks import register_router # type: ignore
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, HTTPException
from starlette.requests import Request # type: ignore

from fps_auth.backends import current_user # type: ignore
Expand Down Expand Up @@ -165,15 +165,14 @@ def get_path_content(path: Path, get_content: bool):
with open(path) as f:
content = f.read()
except Exception:
# FIXME: return error code?
pass
raise HTTPException(status_code=404, detail="Item not found")
format: Optional[str] = None
if path.is_dir():
size = None
type = "directory"
format = "json"
mimetype = None
else:
elif path.is_file():
size = get_file_size(path)
if path.suffix == ".ipynb":
type = "notebook"
Expand All @@ -187,6 +186,8 @@ def get_path_content(path: Path, get_content: bool):
type = "file"
format = None
mimetype = "text/plain"
else:
raise HTTPException(status_code=404, detail="Item not found")

return {
"name": path.name,
Expand Down

0 comments on commit e732e30

Please sign in to comment.