|
17 | 17 |
|
18 | 18 | namespace Google\Cloud\Datastore; |
19 | 19 |
|
| 20 | +use Google\ApiCore\ApiException; |
20 | 21 | use Google\ApiCore\Options\CallOptions; |
21 | 22 | use Google\Cloud\Core\ApiHelperTrait; |
22 | 23 | use Google\Cloud\Core\OptionsValidator; |
| 24 | +use Google\Cloud\Core\RequestProcessorTrait; |
23 | 25 | use Google\Cloud\Core\Timestamp; |
24 | 26 | use Google\Cloud\Core\TimestampTrait; |
25 | 27 | use Google\Cloud\Core\ValidateTrait; |
@@ -67,6 +69,7 @@ class Operation |
67 | 69 | use ValidateTrait; |
68 | 70 | use TimestampTrait; |
69 | 71 | use ApiHelperTrait; |
| 72 | + use RequestProcessorTrait; |
70 | 73 |
|
71 | 74 | /** |
72 | 75 | * @var Serializer |
@@ -295,7 +298,11 @@ public function beginTransaction(array $transactionOptions, array $options = []) |
295 | 298 | CallOptions::class |
296 | 299 | ); |
297 | 300 |
|
298 | | - $res = $this->gapicClient->beginTransaction($beginTransactionRequest, $callOptions); |
| 301 | + try { |
| 302 | + $res = $this->gapicClient->beginTransaction($beginTransactionRequest, $callOptions); |
| 303 | + } catch (ApiException $ex) { |
| 304 | + throw $this->convertToGoogleException($ex); |
| 305 | + } |
299 | 306 |
|
300 | 307 | return base64_encode($res->getTransaction()); |
301 | 308 | } |
@@ -357,7 +364,11 @@ public function allocateIds(array $keys, array $options = []) |
357 | 364 | CallOptions::class |
358 | 365 | ); |
359 | 366 |
|
360 | | - $allocateIdsResponse = $this->gapicClient->allocateIds($allocateIdsRequest, $callOptions); |
| 367 | + try { |
| 368 | + $allocateIdsResponse = $this->gapicClient->allocateIds($allocateIdsRequest, $callOptions); |
| 369 | + } catch (ApiException $ex) { |
| 370 | + throw $this->convertToGoogleException($ex); |
| 371 | + } |
361 | 372 |
|
362 | 373 | /** @var ProtobufKey $responseKey */ |
363 | 374 | foreach ($allocateIdsResponse->getKeys() as $index => $responseKey) { |
@@ -444,7 +455,11 @@ public function lookup(array $keys, array $options = []): array |
444 | 455 | $lookupRequest->setReadOptions($readOptions); |
445 | 456 | } |
446 | 457 |
|
447 | | - $lookupResponse = $this->gapicClient->lookup($lookupRequest, $callOptions); |
| 458 | + try { |
| 459 | + $lookupResponse = $this->gapicClient->lookup($lookupRequest, $callOptions); |
| 460 | + } catch (ApiException $ex) { |
| 461 | + throw $this->convertToGoogleException($ex); |
| 462 | + } |
448 | 463 |
|
449 | 464 | $result = [ |
450 | 465 | 'result' => [], |
@@ -590,7 +605,11 @@ public function runQuery(QueryInterface $query, array $options = []): EntityIter |
590 | 605 | $runQueryRequest->setReadOptions($readOptions); |
591 | 606 | } |
592 | 607 |
|
593 | | - $runQueryResponse = $this->gapicClient->runQuery($runQueryRequest, $callOptions); |
| 608 | + try { |
| 609 | + $runQueryResponse = $this->gapicClient->runQuery($runQueryRequest, $callOptions); |
| 610 | + } catch (ApiException $ex) { |
| 611 | + throw $this->convertToGoogleException($ex); |
| 612 | + } |
594 | 613 |
|
595 | 614 | // When executing a GQL Query, the server will compute a query object |
596 | 615 | // and return it with the first response batch. |
@@ -694,8 +713,12 @@ public function runAggregationQuery(AggregationQuery $runQueryObj, array $option |
694 | 713 | $runAggregationQueryRequest->setReadOptions($readOptions); |
695 | 714 | } |
696 | 715 |
|
697 | | - $runAggregationQueryResponse = $this->gapicClient |
698 | | - ->runAggregationQuery($runAggregationQueryRequest, $callOptions); |
| 716 | + try { |
| 717 | + $runAggregationQueryResponse = $this->gapicClient |
| 718 | + ->runAggregationQuery($runAggregationQueryRequest, $callOptions); |
| 719 | + } catch (ApiException $ex) { |
| 720 | + throw $this->convertToGoogleException($ex); |
| 721 | + } |
699 | 722 |
|
700 | 723 | $res = $this->serializer->encodeMessage($runAggregationQueryResponse); |
701 | 724 |
|
@@ -744,7 +767,11 @@ public function commit(array $mutations, array $options = []) |
744 | 767 | : MODE::TRANSACTIONAL |
745 | 768 | ); |
746 | 769 |
|
747 | | - $commitResponse = $this->gapicClient->commit($commitRequest, $callOptions); |
| 770 | + try { |
| 771 | + $commitResponse = $this->gapicClient->commit($commitRequest, $callOptions); |
| 772 | + } catch (ApiException $ex) { |
| 773 | + throw $this->convertToGoogleException($ex); |
| 774 | + } |
748 | 775 |
|
749 | 776 | return $this->serializer->encodeMessage($commitResponse); |
750 | 777 | } |
@@ -836,7 +863,11 @@ public function rollback(string $transactionId): void |
836 | 863 | ->setDatabaseId($this->databaseId) |
837 | 864 | ->setTransaction(base64_decode($transactionId)); |
838 | 865 |
|
839 | | - $this->gapicClient->rollback($rollbackRequest); |
| 866 | + try { |
| 867 | + $this->gapicClient->rollback($rollbackRequest); |
| 868 | + } catch (ApiException $ex) { |
| 869 | + throw $this->convertToGoogleException($ex); |
| 870 | + } |
840 | 871 | } |
841 | 872 |
|
842 | 873 | /** |
|
0 commit comments