CRM-14159 API Add generic options['metadata'] = labels functionality
[civicrm-core.git] / api / class.api.php
index 06bc404ec5a34c51719e9f6bf450d357cf2f4d3b..bd76f1146349f2a57362b348bb8d420b85881681 100644 (file)
@@ -111,10 +111,10 @@ class civicrm_api3 {
     if (isset($config) && isset($config['conf_path'])) {
       define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
       require_once CIVICRM_SETTINGS_PATH;
-      require_once 'CRM/Core/Classloader.php';
+      require_once 'CRM/Core/ClassLoader.php';
       require_once 'api/api.php';
       require_once "api/v3/utils.php";
-      CRM_Core_Classloader::singleton()->register();
+      CRM_Core_ClassLoader::singleton()->register();
       $this->cfg = CRM_Core_Config::singleton();
       $this->init();
     }
@@ -173,18 +173,27 @@ class civicrm_api3 {
       if (curl_errno($ch)) {
         $res = new stdClass;
         $res->is_error = 1;
+        $res->error_message = curl_error($ch);
+        $res->level = "cURL";
         $res->error = array('cURL error' => curl_error($ch));
         return $res;
       }
       curl_close($ch);
-      return json_decode($result);
     }
     else {
       // Should be discouraged, because the API credentials and data
       // are submitted as GET data, increasing chance of exposure..
       $result = file_get_contents($query . '&' . $fields);
-      return json_decode($result);
     }
+    if (!$res = json_decode($result)) {
+      $res = new stdClass;
+      $res->is_error = 1;
+      $res->error_message = 'Unable to parse returned JSON';
+      $res->level = 'json_decode';
+      $res->error = array('Unable to parse returned JSON' => $result);
+      $res->row_result = $result;
+    }
+    return $res;
   }
 
   function call($entity, $action = 'Get', $params = array()) {