-
Notifications
You must be signed in to change notification settings - Fork 167
fix: retry auth.TransportError errors #418
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,18 +14,19 @@ | |
|
|
||
| import requests | ||
|
|
||
| from google.api_core import exceptions | ||
| from google.api_core import exceptions as api_exceptions | ||
| from google.api_core import retry | ||
| from google.auth import exceptions as auth_exceptions | ||
|
|
||
| import json | ||
|
|
||
|
|
||
| _RETRYABLE_TYPES = ( | ||
| exceptions.TooManyRequests, # 429 | ||
| exceptions.InternalServerError, # 500 | ||
| exceptions.BadGateway, # 502 | ||
| exceptions.ServiceUnavailable, # 503 | ||
| exceptions.GatewayTimeout, # 504 | ||
| api_exceptions.TooManyRequests, # 429 | ||
| api_exceptions.InternalServerError, # 500 | ||
| api_exceptions.BadGateway, # 502 | ||
| api_exceptions.ServiceUnavailable, # 503 | ||
| api_exceptions.GatewayTimeout, # 504 | ||
| requests.ConnectionError, | ||
| ) | ||
|
|
||
|
|
@@ -37,8 +38,10 @@ def _should_retry(exc): | |
| """Predicate for determining when to retry.""" | ||
| if isinstance(exc, _RETRYABLE_TYPES): | ||
| return True | ||
| elif isinstance(exc, exceptions.GoogleAPICallError): | ||
| elif isinstance(exc, api_exceptions.GoogleAPICallError): | ||
| return exc.code in _ADDITIONAL_RETRYABLE_STATUS_CODES | ||
| elif isinstance(exc, auth_exceptions.TransportError): | ||
| return _should_retry(exc.args[0]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is clever! Just wanted to check--
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: Point 1)
My understanding is given this information and the way auth.TransportError is created the underlying Exception should be the first parameter of the construction. I think I could go a step further though and only unwrap when we know it's an auth.TransportError so it's scoped to that specific error. Re: Point 2) |
||
| else: | ||
| return False | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer has to be aliased since you're not importing the auth exceptions as well.