From bb76ee5ae9ee28d0b402886c7d9799c8f7f3e865 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Frank=20J=2E=20G=C3=B3mez?= Date: Wed, 28 Sep 2016 16:31:21 -0400 Subject: [PATCH] Catch exceptions and pass data back to the client instead of allowing silent failures. --- CRM/Contact/Page/AJAX.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 342e4883c8..c032cf3925 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -223,9 +223,6 @@ class CRM_Contact_Page_AJAX { CRM_Utils_JSON::output($output); } - /** - * @throws \CiviCRM_API3_Exception - */ public static function relationship() { $relType = CRM_Utils_Request::retrieve('rel_type', 'String', CRM_Core_DAO::$_nullObject, TRUE); $relContactID = CRM_Utils_Request::retrieve('rel_contact', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); @@ -249,13 +246,19 @@ class CRM_Contact_Page_AJAX { // Loop through multiple case clients foreach ($clientList as $i => $sourceContactID) { - $result = civicrm_api3('relationship', 'create', array( - 'case_id' => $caseID, - 'relationship_type_id' => $relTypeId, - "contact_id_$a" => $relContactID, - "contact_id_$b" => $sourceContactID, - 'start_date' => 'now', - )); + try { + $result = civicrm_api3('relationship', 'create', array( + 'case_id' => $caseID, + 'relationship_type_id' => $relTypeId, + "contact_id_$a" => $relContactID, + "contact_id_$b" => $sourceContactID, + 'start_date' => 'now', + )); + } + catch (CiviCRM_API3_Exception $e) { + $ret['is_error'] = 1; + $ret['error_message'] = $e->getMessage(); + } // Save activity only for the primary (first) client if ($i == 0 && empty($result['is_error'])) { CRM_Case_BAO_Case::createCaseRoleActivity($caseID, $result['id'], $relContactID); -- 2.25.1