From a19c29b417f5cbd709c5ec04c30f768c213a4559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 9 Aug 2023 20:27:54 +0100 Subject: [PATCH] Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient. Fixes #1199 --- NEWS | 3 +++ dulwich/client.py | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 13b839d89..ebcc0c734 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,9 @@ * Support ``init.defaultBranch`` config. (Jelmer Vernooij) + * Raise GitProtocolError when encountering HTTP Errors in + HTTPGitClient. (Jelmer Vernooij, #1199) + 0.21.3 2023-02-17 * Add support for ``worktreeconfig`` extension. diff --git a/dulwich/client.py b/dulwich/client.py index dbd46653a..772f8f893 100644 --- a/dulwich/client.py +++ b/dulwich/client.py @@ -1927,6 +1927,8 @@ def _http_request(self, url, headers=None, data=None): redirect_location properties, and read is a consumable read method for the response data. + Raises: + GitProtocolError """ raise NotImplementedError(self._http_request) @@ -2205,13 +2207,16 @@ def _http_request(self, url, headers=None, data=None): req_headers.update(headers) req_headers["Pragma"] = "no-cache" - if data is None: - resp = self.pool_manager.request( - "GET", url, headers=req_headers, preload_content=False) - else: - resp = self.pool_manager.request( - "POST", url, headers=req_headers, body=data, preload_content=False - ) + try: + if data is None: + resp = self.pool_manager.request( + "GET", url, headers=req_headers, preload_content=False) + else: + resp = self.pool_manager.request( + "POST", url, headers=req_headers, body=data, preload_content=False + ) + except urllib3.exceptions.HTTPError as e: + raise GitProtocolError(str(e)) from e if resp.status == 404: raise NotGitRepository()