From 7d4b6af611e5044a7600f104dfef8a23a720143b Mon Sep 17 00:00:00 2001 From: MGSousa <31368750+MGSousa@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:47:59 +0000 Subject: [PATCH 1/5] Added correct http status codes for pull and fetch --- jupyterlab_git/handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index acc486b40..856883f6e 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -198,7 +198,7 @@ async def post(self, path: str = ""): ) if result["code"] != 0: - self.set_status(500) + self.set_status(401) self.finish(json.dumps(result)) @@ -601,7 +601,7 @@ async def post(self, path: str = ""): ) if response["code"] != 0: - self.set_status(500) + self.set_status(401) self.finish(json.dumps(response)) From d0324f3acb167a4d4316d04dd236cd888a5899d7 Mon Sep 17 00:00:00 2001 From: MGSousa <31368750+MGSousa@users.noreply.github.com> Date: Tue, 17 Jan 2023 17:16:23 +0000 Subject: [PATCH 2/5] Infer client err code for clone instead of server err --- jupyterlab_git/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 856883f6e..34e3977ff 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -98,7 +98,7 @@ async def post(self, path: str = ""): ) if response["code"] != 0: - self.set_status(500) + self.set_status(401) self.finish(json.dumps(response)) From 33f29994ca2c1a6b9ca48c598899c7710594b6f1 Mon Sep 17 00:00:00 2001 From: MGSousa <31368750+MGSousa@users.noreply.github.com> Date: Tue, 17 Jan 2023 17:57:17 +0000 Subject: [PATCH 3/5] Added specific http status codes for push action --- jupyterlab_git/handlers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index 34e3977ff..a0c1f067a 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -683,6 +683,8 @@ async def post(self, path: str = ""): set_upstream=True, force=force, ) + if response["code"] != 0: + self.set_status(401) else: response = { "code": 128, @@ -691,9 +693,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)) From e2f3e38ee9a31bf615293b0f7c1f88bc5f27bb85 Mon Sep 17 00:00:00 2001 From: MGSousa <31368750+MGSousa@users.noreply.github.com> Date: Tue, 17 Jan 2023 18:18:54 +0000 Subject: [PATCH 4/5] fix push handler tests --- jupyterlab_git/tests/test_handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyterlab_git/tests/test_handlers.py b/jupyterlab_git/tests/test_handlers.py index d9626795f..8820920a2 100644 --- a/jupyterlab_git/tests/test_handlers.py +++ b/jupyterlab_git/tests/test_handlers.py @@ -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, @@ -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, From 70d5747965c8a1dc422e5f3dc50b59d762e36543 Mon Sep 17 00:00:00 2001 From: Miguel Sousa Date: Mon, 13 Feb 2023 18:37:24 +0000 Subject: [PATCH 5/5] Added fallback for remote actions with 128 error code --- jupyterlab_git/handlers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py index a0c1f067a..135913374 100644 --- a/jupyterlab_git/handlers.py +++ b/jupyterlab_git/handlers.py @@ -98,7 +98,11 @@ async def post(self, path: str = ""): ) if response["code"] != 0: - self.set_status(401) + if response["code"] == 128: + self.set_status(401) + else: + self.set_status(404) + self.finish(json.dumps(response)) @@ -198,7 +202,8 @@ async def post(self, path: str = ""): ) if result["code"] != 0: - self.set_status(401) + self.set_status(404) + self.finish(json.dumps(result)) @@ -601,7 +606,7 @@ async def post(self, path: str = ""): ) if response["code"] != 0: - self.set_status(401) + self.set_status(404) self.finish(json.dumps(response))