Skip to content

Commit

Permalink
retry on transport errors (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
sprsquish authored Aug 9, 2023
1 parent 96262c6 commit b3e00d3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions fauna/http/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,27 @@ def request(
except httpx.InvalidURL as e:
raise ClientError("Invalid URL Format") from e

try:
return HTTPXResponse(self._send_with_retry(3, request))
except (httpx.HTTPError, httpx.InvalidURL) as e:
raise NetworkError("Exception re-raised from HTTP request") from e

def _send_with_retry(
self,
retryCount: int,
request: httpx.Request,
) -> httpx.Response:
try:
response = self._c.send(
request,
stream=False,
)
except (httpx.HTTPError, httpx.InvalidURL) as e:
raise NetworkError("Exception re-raised from HTTP request") from e

return HTTPXResponse(response)
return response
except httpx.TransportError as e:
if retryCount == 0:
raise e
else:
return self._send_with_retry(retryCount - 1, request)

def stream(
self,
Expand Down

0 comments on commit b3e00d3

Please sign in to comment.