Skip to content

Commit

Permalink
feat: retry google.auth TransportError and requests ConnectionError (#…
Browse files Browse the repository at this point in the history
…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 🦕
  • Loading branch information
parthea committed May 3, 2021
1 parent f87bccb commit 6ae04a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions google/api_core/retry.py
Expand Up @@ -62,11 +62,13 @@ def check_if_exists():
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
Expand Down Expand Up @@ -101,6 +103,8 @@ def if_exception_type_predicate(exception):
exceptions.InternalServerError,
exceptions.TooManyRequests,
exceptions.ServiceUnavailable,
requests.exceptions.ConnectionError,
auth_exceptions.TransportError,
)
"""A predicate that checks if an exception is a transient API error.
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_retry.py
Expand Up @@ -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():
Expand All @@ -42,6 +44,8 @@ def test_if_transient_error():
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(""))


Expand Down

0 comments on commit 6ae04a8

Please sign in to comment.