if (!empty($apiRequest['params']['debug'])) {
$data['trace'] = $e->getTraceAsString();
}
- return civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
+ return $this->createError($e->getMessage(), $data, $apiRequest, $e->getCode());
}
/**
$data['trace'] = $e->getTraceAsString();
}
- return civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
+ return $this->createError($e->getMessage(), $data, $apiRequest, $e->getCode());
}
/**
$data['tip'] = "add debug=1 to your API call to have more info about the error";
}
- return civicrm_api3_create_error($e->getMessage(), $data, $apiRequest);
+ return $this->createError($e->getMessage(), $data, $apiRequest);
+ }
+
+ /**
+ *
+ * @param <type> $data
+ * @param array $data
+ * @param object $apiRequest DAO / BAO object to be freed here
+ *
+ * @throws API_Exception
+ * @return array <type>
+ */
+ function createError($msg, $data, $apiRequest, $code = NULL) {
+ // FIXME what to do with $code?
+ if ($msg == 'DB Error: constraint violation' || substr($msg, 0, 9) == 'DB Error:' || $msg == 'DB Error: already exists') {
+ try {
+ $fields = _civicrm_api3_api_getfields($apiRequest);
+ _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params'], $fields, TRUE);
+ } catch (Exception $e) {
+ $msg = $e->getMessage();
+ }
+ }
+
+ $data = civicrm_api3_create_error($msg, $data);
+
+ if (isset($apiRequest['params']) && is_array($apiRequest['params']) && !empty($apiRequest['params']['api.has_parent'])) {
+ $errorCode = empty($data['error_code']) ? 'chained_api_failed' : $data['error_code'];
+ throw new \API_Exception('Error in call to ' . $apiRequest['entity'] . '_' . $apiRequest['action'] . ' : ' . $msg, $errorCode, $data);
+ }
+
+ return $data;
}
/**
*
* @param <type> $data
* @param array $data
- * @param array $dao (misnomer) apiRequest which led to this error (with keys "entity", "action", etc)
*
* @throws API_Exception
* @return array <type>
*/
-function civicrm_api3_create_error($msg, $data = array(), &$dao = NULL) {
- if (is_array($dao)) {
- if ($msg == 'DB Error: constraint violation' || substr($msg, 0,9) == 'DB Error:' || $msg == 'DB Error: already exists') {
- try {
- $fields = _civicrm_api3_api_getfields($dao);
- _civicrm_api3_validate_fields($dao['entity'], $dao['action'], $dao['params'], $fields, TRUE);
- }
- catch(Exception $e) {
- $msg = $e->getMessage();
- }
- }
- }
+function civicrm_api3_create_error($msg, $data = array()) {
$data['is_error'] = 1;
$data['error_message'] = $msg;
- // we will show sql to privelledged user only (not sure of a specific
- // security hole here but seems sensible - perhaps should apply to the trace as well?
+ // we will show sql to privileged user only (not sure of a specific
+ // security hole here but seems sensible - perhaps should apply to the trace as well?)
if(isset($data['sql']) && CRM_Core_Permission::check('Administer CiviCRM')) {
$data['debug_information'] = $data['sql']; // Isn't this redundant?
} else {
unset($data['sql']);
}
- if (is_array($dao) && isset($dao['params']) && is_array($dao['params']) && !empty($dao['params']['api.has_parent'])) {
- $errorCode = empty($data['error_code']) ? 'chained_api_failed' : $data['error_code'];
- throw new API_Exception('Error in call to ' . $dao['entity'] . '_' . $dao['action'] . ' : ' . $msg, $errorCode, $data);
- }
return $data;
}