Skip to content

Commit

Permalink
contents handler 404 rather than raise exc
Browse files Browse the repository at this point in the history
  • Loading branch information
bloomsa committed Nov 8, 2023
1 parent f282873 commit 252e8a2
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
from http import HTTPStatus

try:
from jupyter_client.jsonutil import json_default
Expand Down Expand Up @@ -116,18 +117,26 @@ async def get(self, path=""):
content = int(content_str or "")

if not cm.allow_hidden and await ensure_async(cm.is_hidden(path)):
raise web.HTTPError(404, f"file or directory {path!r} does not exist")

model = await ensure_async(
self.contents_manager.get(
path=path,
type=type,
format=format,
content=content,
self.set_status(HTTPStatus.NOT_FOUND)
self.write(f"file or directory {path!r} does not exist")
await self.finish()
try:
model = await ensure_async(
self.contents_manager.get(
path=path,
type=type,
format=format,
content=content,
)
)
)
validate_model(model, expect_content=content)
self._finish_model(model, location=False)
validate_model(model, expect_content=content)
self._finish_model(model, location=False)
except web.HTTPError as exc:
if exc.status_code == HTTPStatus.NOT_FOUND:
self.set_status(HTTPStatus.NOT_FOUND)
self.write(f"file or directory {path!r} does not exist")
await self.finish()
raise

@web.authenticated
@authorized
Expand Down

0 comments on commit 252e8a2

Please sign in to comment.