-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add google.api.core.exceptions #3738
Conversation
@@ -0,0 +1,399 @@ | |||
# Copyright 2014 Google Inc. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/exceptions.py
Outdated
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Exceptions raised by Google API core & clients.""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
class GoogleAPIError(Exception): | ||
"""Base class for all exceptions raised by Google API Clients.""" | ||
pass |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
|
||
class _GoogleAPICallErrorMeta(type): | ||
"""Metaclass for registering GoogleAPICallError subclasses.""" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/exceptions.py
Outdated
"""Base class for exceptions raised by calling API methods.""" | ||
|
||
code = None | ||
"""int: The HTTP status code associated with this error. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
except ValueError: | ||
payload = {'error': {'message': response.text or 'unknown error'}} | ||
|
||
error_message = payload.get('error', {}).get('message', 'unknown error') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/exceptions.py
Outdated
|
||
exception = from_http_status( | ||
response.status_code, message, errors=errors) | ||
exception.response = response |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
core/google/api/core/exceptions.py
Outdated
|
||
if error.grpc_status_code is None: | ||
error.grpc_status_code = status_code | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GoogleAPICallError: An instance of the appropriate subclass of | ||
:class:`GoogleAPICallError`. | ||
""" | ||
if isinstance(rpc_exc, grpc.Call): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -0,0 +1,159 @@ | |||
# Copyright 2014 Google Inc. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I think I addressed all comments. Test coverage also fixed, thanks @tseaver. |
core/google/api/core/exceptions.py
Outdated
|
||
@property | ||
def response(self): | ||
"""Optional[Union[requests.Request, grpc.Call]]L The response or |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GoogleAPICallError: An instance of the appropriate subclass of | ||
:class:`GoogleAPICallError`. | ||
""" | ||
if isinstance(rpc_exc, grpc.Call): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes @lukesneeringer are we good to merge? (pending CI)? |
LGTM |
Thanks all ✨ this is the first step to a unified core. :) |
* Add google.api.core.exceptions * Add google.api.core to coverage report * Alias google.cloud.exceptions to google.api.core.exceptions * Fix lint * Address review comments * Fix typo
* Add google.api.core.exceptions * Add google.api.core to coverage report * Alias google.cloud.exceptions to google.api.core.exceptions * Fix lint * Address review comments * Fix typo
* Add google.api.core.exceptions * Add google.api.core to coverage report * Alias google.cloud.exceptions to google.api.core.exceptions * Fix lint * Address review comments * Fix typo
No description provided.