From: Frank J. Gómez Date: Wed, 28 Sep 2016 20:31:21 +0000 (-0400) Subject: Catch exceptions and pass data back to the client instead of allowing silent failures. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bb76ee5ae9ee28d0b402886c7d9799c8f7f3e865;p=civicrm-core.git Catch exceptions and pass data back to the client instead of allowing silent failures. --- 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);