From b89b71f6a88ccee0a4988abc495f86de44b04edd Mon Sep 17 00:00:00 2001 From: David McKee Date: Thu, 19 Oct 2023 12:26:03 +0100 Subject: [PATCH] Catch if the response is None to make typelinting happy --- src/caselawclient/Client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/caselawclient/Client.py b/src/caselawclient/Client.py index c6b740fc..183a9af4 100644 --- a/src/caselawclient/Client.py +++ b/src/caselawclient/Client.py @@ -63,6 +63,12 @@ DEFAULT_USER_AGENT = f"ds-caselaw-marklogic-api-client/{VERSION}" +class NoResponse(Exception): + """A requests HTTPError has no response. We expect this will never happen.""" + + pass + + class MultipartResponseLongerThanExpected(Exception): """ MarkLogic has returned a multipart response with more than one part, where only a single part was expected. @@ -236,6 +242,8 @@ def _raise_for_status(self, response: requests.Response) -> None: try: response.raise_for_status() except requests.exceptions.HTTPError as e: + if e.response is None: + raise NoResponse status_code = e.response.status_code new_error_class = self.http_error_classes.get( status_code, self.default_http_error_class