Browse Source

Don't try to read response if it fails

Peter Richter 4 years ago
parent
commit
d0f294218b
1 changed files with 9 additions and 5 deletions
  1. 9 5
      tripal_chado/includes/TripalImporter/TaxonomyImporter.inc

+ 9 - 5
tripal_chado/includes/TripalImporter/TaxonomyImporter.inc

@@ -721,14 +721,18 @@ class TaxonomyImporter extends TripalImporter {
     }
 
     // Get the search response from NCBI.
+    $xml = FALSE;
     $rfh = fopen($fetch_url, "r");
-    $xml_text = '';
-    while (!feof($rfh)) {
-      $xml_text .= fread($rfh, 255);
+    if ($rfh) {
+      $xml_text = '';
+      while (!feof($rfh)) {
+        $xml_text .= fread($rfh, 255);
+      }
+      fclose($rfh);
+
+      $xml = new SimpleXMLElement($xml_text);
     }
-    fclose($rfh);
 
-    $xml = new SimpleXMLElement($xml_text);
     if ($xml) {
       $taxon = $xml->Taxon;