Skip to content

Commit a21dd6b

Browse files
authored
feat: Raise GoogleAPICallError on REST response errors (#891)
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.
1 parent 16ca92f commit a21dd6b

File tree

1 file changed

+7
-4
lines changed
  • packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports

1 file changed

+7
-4
lines changed

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ from typing import Callable, Dict, Optional, Sequence, Tuple
99
from google.api_core import operations_v1
1010
{% endif %}
1111
from google.api_core import gapic_v1 # type: ignore
12-
from google.auth import credentials as ga_credentials # type: ignore
13-
from google.auth.transport.grpc import SslCredentials # type: ignore
12+
from google.api_core import exceptions as core_exceptions # type: ignore
13+
from google.auth import credentials as ga_credentials # type: ignore
14+
from google.auth.transport.grpc import SslCredentials # type: ignore
1415

1516
import grpc # type: ignore
1617

@@ -214,8 +215,10 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
214215
{% endif %}
215216
)
216217

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

221224
# Return the response

0 commit comments

Comments
 (0)