You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/04/12 22:21:00 UTC
[2/3] git commit: catching "service resource not found" exception in
create_entity
catching "service resource not found" exception in create_entity
create_entity tries to fetch an entity prior to creating one.
This might raise an UG_401_Unauthorized exception which is not caught though it is to be expected.
Now it is okay to save the new entity if the exception message equals 'org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' (are there any constants for that?), any other types of exceptions will be thrown on.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ab1acb8b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ab1acb8b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ab1acb8b
Branch: refs/pull/104/merge
Commit: ab1acb8befe07d95265b86d216b10a1413fd6994
Parents: e7ea1a1
Author: timwillsie <ti...@gmail.com>
Authored: Sat Apr 12 21:22:24 2014 +0200
Committer: timwillsie <ti...@gmail.com>
Committed: Sat Apr 12 21:22:24 2014 +0200
----------------------------------------------------------------------
sdks/php/lib/vendor/Apigee/Usergrid/Client.php | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ab1acb8b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
----------------------------------------------------------------------
diff --git a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
index ea98b42..dcc82f5 100755
--- a/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
+++ b/sdks/php/lib/vendor/Apigee/Usergrid/Client.php
@@ -518,10 +518,23 @@ class Client {
* @return \Apigee\Usergrid\Entity
*/
public function create_entity($entity_data) {
- $entity = new Entity($this, $entity_data);
- $response = $entity->fetch();
+ $entity = new Entity($this, $entity_data);
+ $ok_to_save = null;
+
+ try {
+ $response = $entity->fetch();
+ } catch (UG_401_Unauthorized $ex) {
+ // this is to be expected if the resource doesn't exist yet...
+ if ('org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException' !== $ex->getMessage()) {
+ // ...otherwise throw the exception
+ throw $ex;
+ }
+ $ok_to_save = true;
+ }
$ok_to_save = (
+ $ok_to_save
+ ||
($response->get_error() && ('service_resource_not_found' == $response->get_error_code() || 'no_name_specified' == $response->get_error_code() || 'null_pointer' == $response->get_error_code() ))
||
(!$response->get_error() && array_key_exists('getOnExist', $entity_data) && $entity_data['getOnExist'])