Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/api_core/exceptions.py: 61%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

233 statements  

1# Copyright 2014 Google LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15"""Exceptions raised by Google API core & clients. 

16 

17This module provides base classes for all errors raised by libraries based 

18on :mod:`google.api_core`, including both HTTP and gRPC clients. 

19""" 

20 

21from __future__ import absolute_import, unicode_literals 

22 

23import http.client 

24import warnings 

25from typing import Dict, Optional 

26 

27from google.rpc import error_details_pb2 

28 

29 

30def _warn_could_not_import_grpcio_status(): 

31 warnings.warn( 

32 "Please install grpcio-status to obtain helpful grpc error messages.", 

33 ImportWarning, 

34 ) # pragma: NO COVER 

35 

36 

37try: 

38 import grpc 

39 

40 try: 

41 from grpc_status import rpc_status 

42 except ImportError: # pragma: NO COVER 

43 _warn_could_not_import_grpcio_status() 

44 rpc_status = None 

45except ImportError: # pragma: NO COVER 

46 grpc = None 

47 

48# Lookup tables for mapping exceptions from HTTP and gRPC transports. 

49# Populated by _GoogleAPICallErrorMeta 

50_HTTP_CODE_TO_EXCEPTION: Dict[int, Exception] = {} 

51_GRPC_CODE_TO_EXCEPTION: Dict[int, Exception] = {} 

52 

53# Additional lookup table to map integer status codes to grpc status code 

54# grpc does not currently support initializing enums from ints 

55# i.e., grpc.StatusCode(5) raises an error 

56_INT_TO_GRPC_CODE = {} 

57if grpc is not None: # pragma: no branch 

58 for x in grpc.StatusCode: 

59 _INT_TO_GRPC_CODE[x.value[0]] = x 

60 

61 

62class GoogleAPIError(Exception): 

63 """Base class for all exceptions raised by Google API Clients.""" 

64 

65 pass 

66 

67 

68class DuplicateCredentialArgs(GoogleAPIError): 

69 """Raised when multiple credentials are passed.""" 

70 

71 pass 

72 

73 

74class RetryError(GoogleAPIError): 

75 """Raised when a function has exhausted all of its available retries. 

76 

77 Args: 

78 message (str): The exception message. 

79 cause (Exception): The last exception raised when retrying the 

80 function. 

81 """ 

82 

83 def __init__(self, message, cause): 

84 super(RetryError, self).__init__(message) 

85 self.message = message 

86 self._cause = cause 

87 

88 @property 

89 def cause(self): 

90 """The last exception raised when retrying the function.""" 

91 return self._cause 

92 

93 def __str__(self): 

94 return "{}, last exception: {}".format(self.message, self.cause) 

95 

96 

97class _GoogleAPICallErrorMeta(type): 

98 """Metaclass for registering GoogleAPICallError subclasses.""" 

99 

100 def __new__(mcs, name, bases, class_dict): 

101 cls = type.__new__(mcs, name, bases, class_dict) 

102 if cls.code is not None: 

103 _HTTP_CODE_TO_EXCEPTION.setdefault(cls.code, cls) 

104 if cls.grpc_status_code is not None: 

105 _GRPC_CODE_TO_EXCEPTION.setdefault(cls.grpc_status_code, cls) 

106 return cls 

107 

108 

109class GoogleAPICallError(GoogleAPIError, metaclass=_GoogleAPICallErrorMeta): 

110 """Base class for exceptions raised by calling API methods. 

111 

112 Args: 

113 message (str): The exception message. 

114 errors (Sequence[Any]): An optional list of error details. 

115 details (Sequence[Any]): An optional list of objects defined in google.rpc.error_details. 

116 response (Union[requests.Request, grpc.Call]): The response or 

117 gRPC call metadata. 

118 error_info (Union[error_details_pb2.ErrorInfo, None]): An optional object containing error info 

119 (google.rpc.error_details.ErrorInfo). 

120 """ 

121 

122 code: Optional[int] = None 

123 """Optional[int]: The HTTP status code associated with this error. 

124 

125 This may be ``None`` if the exception does not have a direct mapping 

126 to an HTTP error. 

127 

128 See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 

129 """ 

130 

131 grpc_status_code: Optional["grpc.StatusCode"] = None 

132 """Optional[grpc.StatusCode]: The gRPC status code associated with this 

133 error. 

134 

135 This may be ``None`` if the exception does not match up to a gRPC error. 

136 """ 

137 

138 def __init__(self, message, errors=(), details=(), response=None, error_info=None): 

139 super(GoogleAPICallError, self).__init__(message) 

140 self.message = message 

141 """str: The exception message.""" 

142 self._errors = errors 

143 self._details = details 

144 self._response = response 

145 self._error_info = error_info 

146 

147 def __str__(self): 

148 error_msg = "{} {}".format(self.code, self.message) 

149 if self.details: 

150 error_msg = "{} {}".format(error_msg, self.details) 

151 # Note: This else condition can be removed once proposal A from 

152 # b/284179390 is implemented. 

153 else: 

154 if self.errors: 

155 errors = [ 

156 f"{error.code}: {error.message}" 

157 for error in self.errors 

158 if hasattr(error, "code") and hasattr(error, "message") 

159 ] 

160 if errors: 

161 error_msg = "{} {}".format(error_msg, "\n".join(errors)) 

162 return error_msg 

163 

164 @property 

165 def reason(self): 

166 """The reason of the error. 

167 

168 Reference: 

169 https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112 

170 

171 Returns: 

172 Union[str, None]: An optional string containing reason of the error. 

173 """ 

174 return self._error_info.reason if self._error_info else None 

175 

176 @property 

177 def domain(self): 

178 """The logical grouping to which the "reason" belongs. 

179 

180 Reference: 

181 https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112 

182 

183 Returns: 

184 Union[str, None]: An optional string containing a logical grouping to which the "reason" belongs. 

185 """ 

186 return self._error_info.domain if self._error_info else None 

187 

188 @property 

189 def metadata(self): 

190 """Additional structured details about this error. 

191 

192 Reference: 

193 https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto#L112 

194 

195 Returns: 

196 Union[Dict[str, str], None]: An optional object containing structured details about the error. 

197 """ 

198 return self._error_info.metadata if self._error_info else None 

199 

200 @property 

201 def errors(self): 

202 """Detailed error information. 

203 

204 Returns: 

205 Sequence[Any]: A list of additional error details. 

206 """ 

207 return list(self._errors) 

208 

209 @property 

210 def details(self): 

211 """Information contained in google.rpc.status.details. 

212 

213 Reference: 

214 https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto 

215 https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto 

216 

217 Returns: 

218 Sequence[Any]: A list of structured objects from error_details.proto 

219 """ 

220 return list(self._details) 

221 

222 @property 

223 def response(self): 

224 """Optional[Union[requests.Request, grpc.Call]]: The response or 

225 gRPC call metadata.""" 

226 return self._response 

227 

228 

229class Redirection(GoogleAPICallError): 

230 """Base class for for all redirection (HTTP 3xx) responses.""" 

231 

232 

233class MovedPermanently(Redirection): 

234 """Exception mapping a ``301 Moved Permanently`` response.""" 

235 

236 code = http.client.MOVED_PERMANENTLY 

237 

238 

239class NotModified(Redirection): 

240 """Exception mapping a ``304 Not Modified`` response.""" 

241 

242 code = http.client.NOT_MODIFIED 

243 

244 

245class TemporaryRedirect(Redirection): 

246 """Exception mapping a ``307 Temporary Redirect`` response.""" 

247 

248 code = http.client.TEMPORARY_REDIRECT 

249 

250 

251class ResumeIncomplete(Redirection): 

252 """Exception mapping a ``308 Resume Incomplete`` response. 

253 

254 .. note:: :attr:`http.client.PERMANENT_REDIRECT` is ``308``, but Google 

255 APIs differ in their use of this status code. 

256 """ 

257 

258 code = 308 

259 

260 

261class ClientError(GoogleAPICallError): 

262 """Base class for all client error (HTTP 4xx) responses.""" 

263 

264 

265class BadRequest(ClientError): 

266 """Exception mapping a ``400 Bad Request`` response.""" 

267 

268 code = http.client.BAD_REQUEST 

269 

270 

271class InvalidArgument(BadRequest): 

272 """Exception mapping a :attr:`grpc.StatusCode.INVALID_ARGUMENT` error.""" 

273 

274 grpc_status_code = grpc.StatusCode.INVALID_ARGUMENT if grpc is not None else None 

275 

276 

277class FailedPrecondition(BadRequest): 

278 """Exception mapping a :attr:`grpc.StatusCode.FAILED_PRECONDITION` 

279 error.""" 

280 

281 grpc_status_code = grpc.StatusCode.FAILED_PRECONDITION if grpc is not None else None 

282 

283 

284class OutOfRange(BadRequest): 

285 """Exception mapping a :attr:`grpc.StatusCode.OUT_OF_RANGE` error.""" 

286 

287 grpc_status_code = grpc.StatusCode.OUT_OF_RANGE if grpc is not None else None 

288 

289 

290class Unauthorized(ClientError): 

291 """Exception mapping a ``401 Unauthorized`` response.""" 

292 

293 code = http.client.UNAUTHORIZED 

294 

295 

296class Unauthenticated(Unauthorized): 

297 """Exception mapping a :attr:`grpc.StatusCode.UNAUTHENTICATED` error.""" 

298 

299 grpc_status_code = grpc.StatusCode.UNAUTHENTICATED if grpc is not None else None 

300 

301 

302class Forbidden(ClientError): 

303 """Exception mapping a ``403 Forbidden`` response.""" 

304 

305 code = http.client.FORBIDDEN 

306 

307 

308class PermissionDenied(Forbidden): 

309 """Exception mapping a :attr:`grpc.StatusCode.PERMISSION_DENIED` error.""" 

310 

311 grpc_status_code = grpc.StatusCode.PERMISSION_DENIED if grpc is not None else None 

312 

313 

314class NotFound(ClientError): 

315 """Exception mapping a ``404 Not Found`` response or a 

316 :attr:`grpc.StatusCode.NOT_FOUND` error.""" 

317 

318 code = http.client.NOT_FOUND 

319 grpc_status_code = grpc.StatusCode.NOT_FOUND if grpc is not None else None 

320 

321 

322class MethodNotAllowed(ClientError): 

323 """Exception mapping a ``405 Method Not Allowed`` response.""" 

324 

325 code = http.client.METHOD_NOT_ALLOWED 

326 

327 

328class Conflict(ClientError): 

329 """Exception mapping a ``409 Conflict`` response.""" 

330 

331 code = http.client.CONFLICT 

332 

333 

334class AlreadyExists(Conflict): 

335 """Exception mapping a :attr:`grpc.StatusCode.ALREADY_EXISTS` error.""" 

336 

337 grpc_status_code = grpc.StatusCode.ALREADY_EXISTS if grpc is not None else None 

338 

339 

340class Aborted(Conflict): 

341 """Exception mapping a :attr:`grpc.StatusCode.ABORTED` error.""" 

342 

343 grpc_status_code = grpc.StatusCode.ABORTED if grpc is not None else None 

344 

345 

346class LengthRequired(ClientError): 

347 """Exception mapping a ``411 Length Required`` response.""" 

348 

349 code = http.client.LENGTH_REQUIRED 

350 

351 

352class PreconditionFailed(ClientError): 

353 """Exception mapping a ``412 Precondition Failed`` response.""" 

354 

355 code = http.client.PRECONDITION_FAILED 

356 

357 

358class RequestRangeNotSatisfiable(ClientError): 

359 """Exception mapping a ``416 Request Range Not Satisfiable`` response.""" 

360 

361 code = http.client.REQUESTED_RANGE_NOT_SATISFIABLE 

362 

363 

364class TooManyRequests(ClientError): 

365 """Exception mapping a ``429 Too Many Requests`` response.""" 

366 

367 code = http.client.TOO_MANY_REQUESTS 

368 

369 

370class ResourceExhausted(TooManyRequests): 

371 """Exception mapping a :attr:`grpc.StatusCode.RESOURCE_EXHAUSTED` error.""" 

372 

373 grpc_status_code = grpc.StatusCode.RESOURCE_EXHAUSTED if grpc is not None else None 

374 

375 

376class Cancelled(ClientError): 

377 """Exception mapping a :attr:`grpc.StatusCode.CANCELLED` error.""" 

378 

379 # This maps to HTTP status code 499. See 

380 # https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto 

381 code = 499 

382 grpc_status_code = grpc.StatusCode.CANCELLED if grpc is not None else None 

383 

384 

385class ServerError(GoogleAPICallError): 

386 """Base for 5xx responses.""" 

387 

388 

389class InternalServerError(ServerError): 

390 """Exception mapping a ``500 Internal Server Error`` response. or a 

391 :attr:`grpc.StatusCode.INTERNAL` error.""" 

392 

393 code = http.client.INTERNAL_SERVER_ERROR 

394 grpc_status_code = grpc.StatusCode.INTERNAL if grpc is not None else None 

395 

396 

397class Unknown(ServerError): 

398 """Exception mapping a :attr:`grpc.StatusCode.UNKNOWN` error.""" 

399 

400 grpc_status_code = grpc.StatusCode.UNKNOWN if grpc is not None else None 

401 

402 

403class DataLoss(ServerError): 

404 """Exception mapping a :attr:`grpc.StatusCode.DATA_LOSS` error.""" 

405 

406 grpc_status_code = grpc.StatusCode.DATA_LOSS if grpc is not None else None 

407 

408 

409class MethodNotImplemented(ServerError): 

410 """Exception mapping a ``501 Not Implemented`` response or a 

411 :attr:`grpc.StatusCode.UNIMPLEMENTED` error.""" 

412 

413 code = http.client.NOT_IMPLEMENTED 

414 grpc_status_code = grpc.StatusCode.UNIMPLEMENTED if grpc is not None else None 

415 

416 

417class BadGateway(ServerError): 

418 """Exception mapping a ``502 Bad Gateway`` response.""" 

419 

420 code = http.client.BAD_GATEWAY 

421 

422 

423class ServiceUnavailable(ServerError): 

424 """Exception mapping a ``503 Service Unavailable`` response or a 

425 :attr:`grpc.StatusCode.UNAVAILABLE` error.""" 

426 

427 code = http.client.SERVICE_UNAVAILABLE 

428 grpc_status_code = grpc.StatusCode.UNAVAILABLE if grpc is not None else None 

429 

430 

431class GatewayTimeout(ServerError): 

432 """Exception mapping a ``504 Gateway Timeout`` response.""" 

433 

434 code = http.client.GATEWAY_TIMEOUT 

435 

436 

437class DeadlineExceeded(GatewayTimeout): 

438 """Exception mapping a :attr:`grpc.StatusCode.DEADLINE_EXCEEDED` error.""" 

439 

440 grpc_status_code = grpc.StatusCode.DEADLINE_EXCEEDED if grpc is not None else None 

441 

442 

443class AsyncRestUnsupportedParameterError(NotImplementedError): 

444 """Raised when an unsupported parameter is configured against async rest transport.""" 

445 

446 pass 

447 

448 

449class ResumableTransferError(GoogleAPICallError): 

450 """Base class for resumable transfer errors.""" 

451 

452 upload_url: Optional[str] = None 

453 chunk_size: Optional[int] = None 

454 

455 def __init__( 

456 self, 

457 message: str, 

458 *args, 

459 upload_url: Optional[str] = None, 

460 chunk_size: Optional[int] = None, 

461 **kwargs, 

462 ) -> None: 

463 super().__init__(message, *args, **kwargs) 

464 self.upload_url = upload_url 

465 self.chunk_size = chunk_size 

466 

467 

468class TransferStalledError(ResumableTransferError): 

469 """Raised when upload throughput stays below minimum rate past stall timeout.""" 

470 

471 

472class UnseekableStreamError(ResumableTransferError): 

473 """Raised when server recovery requires rewinding a non-seekable stream.""" 

474 

475 

476class UploadCancelledError(ResumableTransferError): 

477 """Raised when the upload is cancelled by the client or server.""" 

478 

479 

480class MissingStatusHeaderError(ResumableTransferError): 

481 """Raised when server response lacks the required X-Goog-Upload-Status header.""" 

482 

483 

484def exception_class_for_http_status(status_code): 

485 """Return the exception class for a specific HTTP status code. 

486 

487 Args: 

488 status_code (int): The HTTP status code. 

489 

490 Returns: 

491 :func:`type`: the appropriate subclass of :class:`GoogleAPICallError`. 

492 """ 

493 return _HTTP_CODE_TO_EXCEPTION.get(status_code, GoogleAPICallError) 

494 

495 

496def from_http_status(status_code, message, **kwargs): 

497 """Create a :class:`GoogleAPICallError` from an HTTP status code. 

498 

499 Args: 

500 status_code (int): The HTTP status code. 

501 message (str): The exception message. 

502 kwargs: Additional arguments passed to the :class:`GoogleAPICallError` 

503 constructor. 

504 

505 Returns: 

506 GoogleAPICallError: An instance of the appropriate subclass of 

507 :class:`GoogleAPICallError`. 

508 """ 

509 error_class = exception_class_for_http_status(status_code) 

510 error = error_class(message, **kwargs) 

511 

512 if error.code is None: 

513 error.code = status_code 

514 

515 return error 

516 

517 

518def _format_rest_error_message(error, method, url): 

519 method = method.upper() if method else None 

520 message = "{method} {url}: {error}".format( 

521 method=method, 

522 url=url, 

523 error=error, 

524 ) 

525 return message 

526 

527 

528# NOTE: We're moving away from `from_http_status` because it expects an aiohttp response compared 

529# to `format_http_response_error` which expects a more abstract response from google.auth and is 

530# compatible with both sync and async response types. 

531# TODO(https://github.com/googleapis/python-api-core/issues/691): Add type hint for response. 

532def format_http_response_error( 

533 response, method: str, url: str, payload: Optional[Dict] = None 

534): 

535 """Create a :class:`GoogleAPICallError` from a google auth rest response. 

536 

537 Args: 

538 response Union[google.auth.transport.Response, google.auth.aio.transport.Response]: The HTTP response. 

539 method Optional(str): The HTTP request method. 

540 url Optional(str): The HTTP request url. 

541 payload Optional(dict): The HTTP response payload. If not passed in, it is read from response for a response type of google.auth.transport.Response. 

542 

543 Returns: 

544 GoogleAPICallError: An instance of the appropriate subclass of 

545 :class:`GoogleAPICallError`, with the message and errors populated 

546 from the response. 

547 """ 

548 if isinstance(payload, list): 

549 payload = next((item for item in payload if isinstance(item, dict)), {}) 

550 payload = {} if not payload else payload 

551 error_message = payload.get("error", {}).get("message", "unknown error") 

552 errors = payload.get("error", {}).get("errors", ()) 

553 # In JSON, details are already formatted in developer-friendly way. 

554 details = payload.get("error", {}).get("details", ()) 

555 error_info_list = list( 

556 filter( 

557 lambda detail: detail.get("@type", "") 

558 == "type.googleapis.com/google.rpc.ErrorInfo", 

559 details, 

560 ) 

561 ) 

562 error_info = error_info_list[0] if error_info_list else None 

563 message = _format_rest_error_message(error_message, method, url) 

564 

565 exception = from_http_status( 

566 response.status_code, 

567 message, 

568 errors=errors, 

569 details=details, 

570 response=response, 

571 error_info=error_info, 

572 ) 

573 return exception 

574 

575 

576def from_http_response(response): 

577 """Create a :class:`GoogleAPICallError` from a :class:`requests.Response`. 

578 

579 Args: 

580 response (requests.Response): The HTTP response. 

581 

582 Returns: 

583 GoogleAPICallError: An instance of the appropriate subclass of 

584 :class:`GoogleAPICallError`, with the message and errors populated 

585 from the response. 

586 """ 

587 try: 

588 payload = response.json() 

589 except ValueError: 

590 payload = {"error": {"message": response.text or "unknown error"}} 

591 return format_http_response_error( 

592 response, response.request.method, response.request.url, payload 

593 ) 

594 

595 

596def exception_class_for_grpc_status(status_code): 

597 """Return the exception class for a specific :class:`grpc.StatusCode`. 

598 

599 Args: 

600 status_code (grpc.StatusCode): The gRPC status code. 

601 

602 Returns: 

603 :func:`type`: the appropriate subclass of :class:`GoogleAPICallError`. 

604 """ 

605 return _GRPC_CODE_TO_EXCEPTION.get(status_code, GoogleAPICallError) 

606 

607 

608def from_grpc_status(status_code, message, **kwargs): 

609 """Create a :class:`GoogleAPICallError` from a :class:`grpc.StatusCode`. 

610 

611 Args: 

612 status_code (Union[grpc.StatusCode, int]): The gRPC status code. 

613 message (str): The exception message. 

614 kwargs: Additional arguments passed to the :class:`GoogleAPICallError` 

615 constructor. 

616 

617 Returns: 

618 GoogleAPICallError: An instance of the appropriate subclass of 

619 :class:`GoogleAPICallError`. 

620 """ 

621 

622 if isinstance(status_code, int): 

623 status_code = _INT_TO_GRPC_CODE.get(status_code, status_code) 

624 

625 error_class = exception_class_for_grpc_status(status_code) 

626 error = error_class(message, **kwargs) 

627 

628 if error.grpc_status_code is None: 

629 error.grpc_status_code = status_code 

630 

631 return error 

632 

633 

634def _is_informative_grpc_error(rpc_exc): 

635 return hasattr(rpc_exc, "code") and hasattr(rpc_exc, "details") 

636 

637 

638def _parse_grpc_error_details(rpc_exc): 

639 if not rpc_status: # pragma: NO COVER 

640 _warn_could_not_import_grpcio_status() 

641 return [], None 

642 try: 

643 status = rpc_status.from_call(rpc_exc) 

644 except NotImplementedError: # workaround 

645 return [], None 

646 

647 if not status: 

648 return [], None 

649 

650 possible_errors = [ 

651 error_details_pb2.BadRequest, 

652 error_details_pb2.PreconditionFailure, 

653 error_details_pb2.QuotaFailure, 

654 error_details_pb2.ErrorInfo, 

655 error_details_pb2.RetryInfo, 

656 error_details_pb2.ResourceInfo, 

657 error_details_pb2.RequestInfo, 

658 error_details_pb2.DebugInfo, 

659 error_details_pb2.Help, 

660 error_details_pb2.LocalizedMessage, 

661 ] 

662 error_info = None 

663 error_details = [] 

664 for detail in status.details: 

665 matched_detail_cls = list( 

666 filter(lambda x: detail.Is(x.DESCRIPTOR), possible_errors) 

667 ) 

668 # If nothing matched, use detail directly. 

669 if len(matched_detail_cls) == 0: 

670 info = detail 

671 else: 

672 info = matched_detail_cls[0]() 

673 detail.Unpack(info) 

674 error_details.append(info) 

675 if isinstance(info, error_details_pb2.ErrorInfo): 

676 error_info = info 

677 return error_details, error_info 

678 

679 

680def from_grpc_error(rpc_exc): 

681 """Create a :class:`GoogleAPICallError` from a :class:`grpc.RpcError`. 

682 

683 Args: 

684 rpc_exc (grpc.RpcError): The gRPC error. 

685 

686 Returns: 

687 GoogleAPICallError: An instance of the appropriate subclass of 

688 :class:`GoogleAPICallError`. 

689 """ 

690 # NOTE(lidiz) All gRPC error shares the parent class grpc.RpcError. 

691 # However, check for grpc.RpcError breaks backward compatibility. 

692 if ( 

693 grpc is not None and isinstance(rpc_exc, grpc.Call) 

694 ) or _is_informative_grpc_error(rpc_exc): 

695 details, err_info = _parse_grpc_error_details(rpc_exc) 

696 message = rpc_exc.details() 

697 if ( 

698 grpc is not None 

699 and rpc_exc.code() == grpc.StatusCode.UNIMPLEMENTED 

700 and "Received http2 header with status: 404" in message 

701 ): 

702 message = ( 

703 f"{message}. This usually indicates that the 'api_endpoint' " 

704 "configuration in ClientOptions is incorrect, contains a typo, " 

705 "or is an invalid regional endpoint for this service." 

706 ) 

707 return from_grpc_status( 

708 rpc_exc.code(), 

709 message, 

710 errors=(rpc_exc,), 

711 details=details, 

712 response=rpc_exc, 

713 error_info=err_info, 

714 ) 

715 else: 

716 return GoogleAPICallError(str(rpc_exc), errors=(rpc_exc,), response=rpc_exc)