Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 when content not found #126

Merged
merged 1 commit into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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