Skip to content
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

Merged
merged 6 commits into from
Aug 8, 2017

Conversation

theacodes
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 7, 2017
@@ -0,0 +1,399 @@
# Copyright 2014 Google Inc.

This comment was marked as spam.

This comment was marked as spam.

# 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.


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.



class _GoogleAPICallErrorMeta(type):
"""Metaclass for registering GoogleAPICallError subclasses."""

This comment was marked as spam.

"""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.

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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


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.


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.

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.

This comment was marked as spam.

@@ -0,0 +1,159 @@
# Copyright 2014 Google Inc.

This comment was marked as spam.

@tseaver
Copy link
Contributor

tseaver commented Aug 7, 2017

@theacodes
Copy link
Contributor Author

I think I addressed all comments. Test coverage also fixed, thanks @tseaver.


@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.

GoogleAPICallError: An instance of the appropriate subclass of
:class:`GoogleAPICallError`.
"""
if isinstance(rpc_exc, grpc.Call):

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

@dhermes @lukesneeringer are we good to merge? (pending CI)?

@dhermes
Copy link
Contributor

dhermes commented Aug 8, 2017

LGTM

@theacodes theacodes merged commit abfec70 into googleapis:master Aug 8, 2017
@theacodes
Copy link
Contributor Author

Thanks all ✨ this is the first step to a unified core. :)

@theacodes theacodes deleted the api-core-exceptions branch August 8, 2017 17:32
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 21, 2017
* 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
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* 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
landrito pushed a commit to landrito/google-cloud-python that referenced this pull request Aug 22, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: core cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants