Admin: Home: Properly handles Request_HTTP exceptions now
authorDan
Mon, 04 May 2009 23:06:33 -0400
changeset 951 745cccc6b97d
parent 950 36289dcb5c8a
child 952 d52dfa1f08da
Admin: Home: Properly handles Request_HTTP exceptions now
plugins/admin/Home.php
--- a/plugins/admin/Home.php	Mon May 04 23:05:52 2009 -0400
+++ b/plugins/admin/Home.php	Mon May 04 23:06:33 2009 -0400
@@ -156,15 +156,26 @@
 {
   require_once(ENANO_ROOT . '/includes/http.php');
   
-  $req = new Request_HTTP('ktulu.enanocms.org', '/meta/updates.xml');
-  $response = $req->get_response_body();
-  header('Content-type: application/xml');
+  try
+  {
+    $req = new Request_HTTP('ktulu.enanocms.org', '/meta/updates.xml');
+    $response = $req->get_response_body();
+    header('Content-type: application/xml');
+  }
+  catch ( Exception $e )
+  {
+    header('Content-type: application/xml');
+    echo '<enano><error><![CDATA[
+Cannot connect to server: ' . $e->getMessage() . '
+]]></error></enano>';
+    return true;
+  }
   if ( $req->response_code != HTTP_OK )
   {
     // Error in response
-    echo '<enano><latest><error><![CDATA[
+    echo '<enano><error><![CDATA[
 Did not properly receive response from server. Response code: ' . $req->response_code . ' ' . $req->response_string . '
-]]></error></latest></enano>';
+]]></error></enano>';
   }
   else
   {
@@ -172,9 +183,9 @@
     $first_update = preg_match('/<release tag="([^"]+)" version="([^"]+)" (codename="([^"]+)" )?relnotes="([^"]+)" ?\/>/', $response, $match);
     if ( !$first_update )
     {
-      echo '<enano><latest><error><![CDATA[
+      echo '<enano><error><![CDATA[
 Received invalid XML response.
-]]></error></latest></enano>';
+]]></error></enano>';
     }
     else
     {