Browse Source

Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient.

Fixes #1199
Jelmer Vernooij 1 year ago
parent
commit
a5e47fe514
2 changed files with 15 additions and 7 deletions
  1. 3 0
      NEWS
  2. 12 7
      dulwich/client.py

+ 3 - 0
NEWS

@@ -17,6 +17,9 @@
  * objects: Define a stricter return type for _parse_message
    (Vincent Lorentz)
 
+ * Raise GitProtocolError when encountering HTTP Errors in
+   HTTPGitClient. (Jelmer Vernooij, #1199)
+
 0.21.5	2023-05-04
 
  * Be more tolerant to non-3-length tuple versions.

+ 12 - 7
dulwich/client.py

@@ -1949,6 +1949,8 @@ class AbstractHttpGitClient(GitClient):
           redirect_location properties, and read is a consumable read
           method for the response data.
 
+        Raises:
+          GitProtocolError
         """
         raise NotImplementedError(self._http_request)
 
@@ -2225,13 +2227,16 @@ class Urllib3HttpGitClient(AbstractHttpGitClient):
             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()