Return a CiviCRM-looking error if we hit a cURL error.
authorChris Burgess <chris@giantrobot.co.nz>
Fri, 31 May 2013 00:59:44 +0000 (12:59 +1200)
committerChris Burgess <chris@giantrobot.co.nz>
Fri, 31 May 2013 02:51:14 +0000 (14:51 +1200)
Handle cURL errors by synthesising a CiviCRM error object.

This is API so we can't depend on having CRM_Core_Error::createError() available.

api/class.api.php

index f848ec9cf7a6e78a106e39ee18f551a848a15f45..65c06459ef3a50e189d1db585307cadc89d8164b 100644 (file)
@@ -140,6 +140,13 @@ class civicrm_api3 {
 
       //execute post
       $result = curl_exec($ch);
+      // CiviCRM expects to get back a CiviCRM error object.
+      if (curl_errno($ch)) {
+          $res = new stdClass;
+          $res->is_error = 1;
+          $res->error = array('cURL error' => curl_error($ch));
+          return $res;
+      }      
       curl_close($ch);
       return json_decode($result);
       // not good, all in get when should be in post.