HTTP: now throws exceptions instead of flat-out dying
authorDan
Sat, 04 Apr 2009 22:34:56 -0400
changeset 894 83d180d87f3c
parent 893 b24601274cd2
child 895 d6b095673a47
HTTP: now throws exceptions instead of flat-out dying
includes/http.php
--- a/includes/http.php	Sat Apr 04 22:34:12 2009 -0400
+++ b/includes/http.php	Sat Apr 04 22:34:56 2009 -0400
@@ -199,18 +199,18 @@
   function Request_HTTP($host, $uri, $method = 'GET', $port = 80)
   {
     if ( !preg_match('/^(([a-z0-9-]+\.)*?)([a-z0-9-]+)$/', $host) )
-      die(__CLASS__ . ': Invalid hostname');
+      throw new Exception(__CLASS__ . ': Invalid hostname');
     $this->host = $host;
     $this->uri = $uri;
     if ( is_int($port) && $port >= 1 && $port <= 65535 )
       $this->port = $port;
     else
-      die(__CLASS__ . ': Invalid port');
+      throw new Exception(__CLASS__ . ': Invalid port');
     $method = strtoupper($method);
     if ( $method == 'GET' || $method == 'POST' )
       $this->method = $method;
     else
-      die(__CLASS__ . ': Invalid request method');
+      throw new Exception(__CLASS__ . ': Invalid request method');
       
     $newline = "\r\n";
     $php_ver = PHP_VERSION;
@@ -239,7 +239,7 @@
     }
     else
     {
-      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
+      throw new Exception(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
     }
   }
   
@@ -264,7 +264,7 @@
     }
     else
     {
-      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
+      throw new Exception(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
     }
   }
   
@@ -289,7 +289,7 @@
     }
     else
     {
-      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
+      throw new Exception(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
     }
   }
   
@@ -314,7 +314,7 @@
     }
     else
     {
-      die(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
+      throw new Exception(__CLASS__ . '::' . __METHOD__ . ': Invalid argument(s)');
     }
   }
   
@@ -328,7 +328,7 @@
     // Open connection
     $connection = fsockopen($this->host, $this->port);
     if ( !$connection )
-      die(__CLASS__ . '::' . __METHOD__ . ': Could not make connection');
+      throw new Exception(__CLASS__ . '::' . __METHOD__ . ': Could not make connection');
     
     // 1 = socket open
     $this->state = 1;