Index: DrupalGoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/DrupalGoogleMini.php,v
retrieving revision 1.1.4.3
diff -u -p -r1.1.4.3 DrupalGoogleMini.php
--- DrupalGoogleMini.php	21 Aug 2009 09:08:46 -0000	1.1.4.3
+++ DrupalGoogleMini.php	3 Feb 2010 22:06:15 -0000
@@ -38,7 +38,14 @@ class DrupalGoogleMini extends GoogleMin
       $cached_result_xml = $_cached_result_xml->data;
       $google_debug = variable_get('google_appliance_debug', 0);
       if ($cached_result_xml) {
-        $google_results = GoogleMini::resultFactory($cached_result_xml, $iteratorClass);
+        try {
+          $google_results = GoogleMini::resultFactory($cached_result_xml, $iteratorClass);
+        }
+        catch (Exception $e) {
+          drupal_set_message($e->getMessage(), 'error');
+          watchdog('google_appliance', $e->getMessage());
+          return FALSE;
+        }
         if ($google_debug >= 2 ){
           if (function_exists('dpr')) {
             dpr("got cache for $cache_key");
@@ -49,7 +56,14 @@ class DrupalGoogleMini extends GoogleMin
         }
       }
       else {
-        $google_results = parent::query($iteratorClass);
+        try {
+          $google_results = parent::query($iteratorClass);
+        }
+        catch (Exception $e) {
+          drupal_set_message($e->getMessage(), 'error');
+          watchdog('google_appliance', $e->getMessage());
+          return FALSE;
+        }
         $timeout = variable_get('google_appliance_cache_timeout', 600); // 10 minutes by default
         cache_set($cache_key, $google_results->payload->asXML(), 'cache_google_appliance', time() + $timeout);
         $google_debug = variable_get('google_debug', 0);
Index: GoogleMini.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/google_appliance/GoogleMini.php,v
retrieving revision 1.2.2.3
diff -u -p -r1.2.2.3 GoogleMini.php
--- GoogleMini.php	21 Aug 2009 09:08:46 -0000	1.2.2.3
+++ GoogleMini.php	3 Feb 2010 22:06:16 -0000
@@ -8,7 +8,6 @@ if (!defined('GOOGLE_MINI_MAX_RESULTS'))
 class GoogleMini {
 
   private $_metaDataFilters = array();
-  private $_metaDataRequested = array();
   public  $baseUrl = ''; // REQUIRED
   public  $frontEnd = ''; // IF SET WILL DISABLE parsing of results.
   public  $collection = ''; // REQUIRED
 
@@ -296,26 +295,51 @@ class GoogleMini {
 
 
   public function query($iteratorClass = 'GoogleMiniResultIterator') {
-
     $query = $this->buildQuery();
-    // get search results in XML using cURL
     $ch = curl_init();
-    curl_setopt($ch, CURLOPT_URL, $query);
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
-    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
+    curl_setopt($ch, CURLOPT_URL, $query);            // Set the query URL.
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);   // Return the response during the curl_exec() call, or FALSE on error.
+    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);          // Output errors to STDERR
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);  // Allow the cURL request to succeed even if the Google Mini server's SSL certificate isn't valid.
+    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  // This way, you can serve the Google Mini using https without having to maintain an SSL certficate.
+
+    // Set this to a large number if connections aren't being made. Set to 0 for infinite timeout.
+    if ($timeout = variable_get('google_appliance_timeout', FALSE)) {
+      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+    }
 
+    // send request
     $resultXML = curl_exec($ch);
-	if ($this->debug) {
-    	$this->log('Made CURL request to '. $query);
-	}
+    if ($this->debug) {
+      $this->log('Made cURL request to '. $query);
+    }
 
+    // handle errors if cURL request fails
+    if (!$resultXML) {
+      if ($this->debug) {
+        $this->log('cURL error #'. curl_errno($ch) .': '. curl_error($ch));
+      }
+      throw new GoogleMiniResultException('There was a cURL error while connecting with the Google device.');
+      return FALSE;
+    }
+
+    // if request succeeded, return formatted result set
     return self::resultFactory($resultXML, $iteratorClass);
   }
 
   function resultFactory($resultXML, $className = 'GoogleMiniResultIterator') {
     $results = array();
 
-    $payload = simplexml_load_string($resultXML);
+    libxml_use_internal_errors(TRUE);
+    if (!$payload = simplexml_load_string($resultXML)) {
+      $errors = array();
+      foreach (libxml_get_errors() as $error) {
+        $errors[] = $error->message;
+      }
+      $errors = join(', ', $errors);
+      throw new GoogleMiniResultException('There was an error parsing the result XML: '. $errors);
+      return FALSE;
+    }
 
     $totalResults = $payload->RES->M;    
     
