Skip to content

Commit 041d242

Browse files
author
twalder-docnet
committed
Add contention handling and exception
1 parent 06ba401 commit 041d242

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/GDS/Gateway/GoogleAPIClient.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
namespace GDS\Gateway;
1818
use GDS\Entity;
19+
use GDS\Exception\Contention;
1920

2021
/**
2122
* GoogleAPIClient Datastore Gateway
@@ -189,6 +190,8 @@ private function applyTransaction($obj_request) {
189190
*
190191
* @param \Google_Service_Datastore_Mutation $obj_mutation
191192
* @return \Google_Service_Datastore_CommitResponse
193+
* @throws Contention
194+
* @throws \Google_Service_Exception
192195
*/
193196
private function commitMutation(\Google_Service_Datastore_Mutation $obj_mutation)
194197
{
@@ -198,11 +201,19 @@ private function commitMutation(\Google_Service_Datastore_Mutation $obj_mutation
198201
} else {
199202
$obj_request->setMode('TRANSACTIONAL');
200203
$obj_request->setTransaction($this->str_next_transaction);
201-
$this->str_next_transaction = null;
204+
$this->str_next_transaction = NULL;
202205
}
203206
$obj_request->setMutation($obj_mutation);
204-
$this->obj_last_response = $this->obj_datasets->commit($this->str_dataset_id, $obj_request);
205-
return $this->obj_last_response;
207+
try {
208+
$this->obj_last_response = $this->obj_datasets->commit($this->str_dataset_id, $obj_request);
209+
} catch (\Google_Service_Exception $obj_exception) {
210+
$this->obj_last_response = NULL;
211+
if(409 == $obj_exception->getCode()) {
212+
throw new Contention('Datastore contention', 409, $obj_exception);
213+
} else {
214+
throw $obj_exception;
215+
}
216+
}
206217
}
207218

208219
/**
@@ -266,7 +277,7 @@ public function deleteMulti(array $arr_entities)
266277
$this->applyNamespace($obj_key);
267278
}
268279
$obj_mutation->setDelete($arr_google_keys);
269-
$this->obj_last_response = $this->commitMutation($obj_mutation);
280+
$this->commitMutation($obj_mutation);
270281
$this->obj_schema = null;
271282
return TRUE; // really?
272283
}

0 commit comments

Comments
 (0)