diff --git a/dulwich/client.py b/dulwich/client.py index 4962621e3..952f45db5 100644 --- a/dulwich/client.py +++ b/dulwich/client.py @@ -2229,6 +2229,17 @@ def __repr__(self) -> str: return f"{type(self).__name__}({self._base_url!r}, dumb={self.dumb!r})" +def _wrap_urllib3_exceptions(func): + + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except urllib3.exceptions.ProtocolError as error: + raise GitProtocolError(str(error)) from error + + return wrapper + + class Urllib3HttpGitClient(AbstractHttpGitClient): def __init__( self, @@ -2308,7 +2319,7 @@ def _http_request(self, url, headers=None, data=None): resp.redirect_location = resp.get_redirect_location() else: resp.redirect_location = resp_url if resp_url != url else "" - return resp, resp.read + return resp, _wrap_urllib3_exceptions(resp.read) HttpGitClient = Urllib3HttpGitClient