Skip to content

Commit

Permalink
feat: Raise GoogleAPICallError on REST response errors (#891)
Browse files Browse the repository at this point in the history
While testing against Showcase, I found that server errors resulted in a large exception stack dump that did not include the body of the erroring response. This PR shortens the stack dump and prints out the request body.
  • Loading branch information
vchudnov-g authored May 19, 2021
1 parent ce558ac commit edb8c63
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ from typing import Callable, Dict, Optional, Sequence, Tuple
from google.api_core import operations_v1
{% endif %}
from google.api_core import gapic_v1 # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore

import grpc # type: ignore

Expand Down Expand Up @@ -214,8 +215,10 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
{% endif %}
)

# Raise requests.exceptions.HTTPError if the status code is >= 400
response.raise_for_status()
# In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
# subclass.
if response.status_code >= 400:
raise core_exceptions.from_http_response(response)
{% if not method.void %}

# Return the response
Expand Down

0 comments on commit edb8c63

Please sign in to comment.