Skip to content

Commit 6ae04a8

Browse files
authored
feat: retry google.auth TransportError and requests ConnectionError (googleapis#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 googleapis#176 🦕
1 parent f87bccb commit 6ae04a8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

google/api_core/retry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def check_if_exists():
6262
import random
6363
import time
6464

65+
import requests.exceptions
6566
import six
6667

6768
from google.api_core import datetime_helpers
6869
from google.api_core import exceptions
6970
from google.api_core import general_helpers
71+
from google.auth import exceptions as auth_exceptions
7072

7173
_LOGGER = logging.getLogger(__name__)
7274
_DEFAULT_INITIAL_DELAY = 1.0 # seconds
@@ -101,6 +103,8 @@ def if_exception_type_predicate(exception):
101103
exceptions.InternalServerError,
102104
exceptions.TooManyRequests,
103105
exceptions.ServiceUnavailable,
106+
requests.exceptions.ConnectionError,
107+
auth_exceptions.TransportError,
104108
)
105109
"""A predicate that checks if an exception is a transient API error.
106110

tests/unit/test_retry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import mock
2020
import pytest
21+
import requests.exceptions
2122

2223
from google.api_core import exceptions
2324
from google.api_core import retry
25+
from google.auth import exceptions as auth_exceptions
2426

2527

2628
def test_if_exception_type():
@@ -42,6 +44,8 @@ def test_if_transient_error():
4244
assert retry.if_transient_error(exceptions.InternalServerError(""))
4345
assert retry.if_transient_error(exceptions.TooManyRequests(""))
4446
assert retry.if_transient_error(exceptions.ServiceUnavailable(""))
47+
assert retry.if_transient_error(requests.exceptions.ConnectionError(""))
48+
assert retry.if_transient_error(auth_exceptions.TransportError(""))
4549
assert not retry.if_transient_error(exceptions.InvalidArgument(""))
4650

4751

0 commit comments

Comments
 (0)