Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: retry google.auth TransportError and requests ConnectionError #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/api_core/retry.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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