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

Improve HTTP status codes for the some remote git operations #1209

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 12 additions & 6 deletions jupyterlab_git/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ async def post(self, path: str = ""):
)

if response["code"] != 0:
self.set_status(500)
if response["code"] == 128:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot rely on the error code from git to know what went wrong.

It requires parsing the error message - as done already in the frontend:

export const AUTH_ERROR_MESSAGES = [

So we should add the same test here to determine which status to set.

The same comment applies for the fetch, push and pull methods.

self.set_status(401)
else:
self.set_status(404)

self.finish(json.dumps(response))


Expand Down Expand Up @@ -198,7 +202,8 @@ async def post(self, path: str = ""):
)

if result["code"] != 0:
self.set_status(500)
self.set_status(404)

self.finish(json.dumps(result))


Expand Down Expand Up @@ -601,7 +606,7 @@ async def post(self, path: str = ""):
)

if response["code"] != 0:
self.set_status(500)
self.set_status(404)

self.finish(json.dumps(response))

Expand Down Expand Up @@ -683,6 +688,8 @@ async def post(self, path: str = ""):
set_upstream=True,
force=force,
)
if response["code"] != 0:
self.set_status(401)
else:
response = {
"code": 128,
Expand All @@ -691,9 +698,8 @@ async def post(self, path: str = ""):
),
"remotes": remotes, # Returns the list of known remotes
}

if response["code"] != 0:
self.set_status(500)
if response["code"] != 0:
self.set_status(404)

self.finish(json.dumps(response))

Expand Down
4 changes: 2 additions & 2 deletions jupyterlab_git/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ async def test_push_handler_noupstream(mock_git, jp_fetch, jp_root_dir):
mock_git.remote_show.assert_called_with(str(local_path))
mock_git.push.assert_not_called()

assert response.code == 500
assert response.code == 404
payload = json.loads(response.body)
assert payload == {
"code": 128,
Expand Down Expand Up @@ -449,7 +449,7 @@ async def test_push_handler_multipleupstream(mock_git, jp_fetch, jp_root_dir):
mock_git.remote_show.assert_called_with(str(local_path))
mock_git.push.assert_not_called()

assert response.code == 500
assert response.code == 404
payload = json.loads(response.body)
assert payload == {
"code": 128,
Expand Down