feat: retry google.auth TransportError and requests ConnectionError (#178)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-api-core/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
Fixes #176 🦕
diff --git a/google/api_core/retry.py b/google/api_core/retry.py
index 43e4f07..f0f23bc 100644
--- a/google/api_core/retry.py
+++ b/google/api_core/retry.py
@@ -62,11 +62,13 @@
import random
import time
+import requests.exceptions
import six
from google.api_core import datetime_helpers
from google.api_core import exceptions
from google.api_core import general_helpers
+from google.auth import exceptions as auth_exceptions
_LOGGER = logging.getLogger(__name__)
_DEFAULT_INITIAL_DELAY = 1.0 # seconds
@@ -101,6 +103,8 @@
exceptions.InternalServerError,
exceptions.TooManyRequests,
exceptions.ServiceUnavailable,
+ requests.exceptions.ConnectionError,
+ auth_exceptions.TransportError,
)
"""A predicate that checks if an exception is a transient API error.
diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py
index 4c2e457..ce8f417 100644
--- a/tests/unit/test_retry.py
+++ b/tests/unit/test_retry.py
@@ -18,9 +18,11 @@
import mock
import pytest
+import requests.exceptions
from google.api_core import exceptions
from google.api_core import retry
+from google.auth import exceptions as auth_exceptions
def test_if_exception_type():
@@ -42,6 +44,8 @@
assert retry.if_transient_error(exceptions.InternalServerError(""))
assert retry.if_transient_error(exceptions.TooManyRequests(""))
assert retry.if_transient_error(exceptions.ServiceUnavailable(""))
+ assert retry.if_transient_error(requests.exceptions.ConnectionError(""))
+ assert retry.if_transient_error(auth_exceptions.TransportError(""))
assert not retry.if_transient_error(exceptions.InvalidArgument(""))