diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index bf3cec5efc..afb296aeaf 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -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 @@ -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