Catch exceptions from the http client and rethrow them as
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 5 Mar 2009 01:32:04 +0000 (20:32 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 5 Mar 2009 01:33:56 +0000 (20:33 -0500)
Horde_Service_Facebook_Exception if needed.

framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php
framework/Service_Facebook/lib/Horde/Service/Facebook/UploadRequest.php

index c4445be..fffeb1f 100644 (file)
@@ -27,6 +27,8 @@ class Horde_Service_Facebook_Request
     /**
      * Run this request and return the data.
      *
+     * @throws Horde_Service_Facebook_Exception
+     *
      * @param string $dataFormat  Optionally specify the datatype to return.
      *
      * @return Either raw XML, JSON, or an array of decoded values.
@@ -53,6 +55,12 @@ class Horde_Service_Facebook_Request
         return $result;
     }
 
+    /**
+     * @throws Horde_Service_Facebook_Exception
+     * @param $method
+     * @param $params
+     * @return unknown_type
+     */
     protected function _postRequest($method, &$params)
     {
         $this->_finalizeParams($method, $params);
@@ -60,7 +68,13 @@ class Horde_Service_Facebook_Request
         //       we have to manually create the post string or we get an
         //       invalid signature error from FB
         $post_string = $this->_createPostString($params);
-        $result = $this->_http->post(Horde_Service_Facebook::REST_SERVER_ADDR, $post_string);
+        try {
+            $result = $this->_http->post(Horde_Service_Facebook::REST_SERVER_ADDR, $post_string);
+        } catch (Exception $e) {
+            // Not much we can do about a client exception - rethrow it as
+            // temporarily unavailable.
+            throw new Horde_Service_Facebook_Exception(_("Service is unavailable. Please try again later."));
+        }
         return $result->getBody();
     }
 
index 32d9820..4dbe225 100644 (file)
@@ -27,13 +27,11 @@ class Horde_Service_Facebook_UploadRequest extends Horde_Service_Facebook_Reques
     }
 
     /**
-     * TODO
+     * Execute a RFC1867/RFC1341 Multipart Http Transaction.
      *
-     * @param $method
-     * @param $params
-     * @param $file
-     * @param $server_addr
-     * @return unknown_type
+     * @throws Horde_Service_Facebook_Exception
+     *
+     * @return string
      */
     private function _multipartHttpTransaction()
     {
@@ -64,11 +62,16 @@ class Horde_Service_Facebook_UploadRequest extends Horde_Service_Facebook_Reques
         $content_lines[] = $close_delimiter;
         $content_lines[] = '';
         $content = implode("\r\n", $content_lines);
-        $result = $this->_http->request('POST',
-                                        Horde_Service_Facebook::REST_SERVER_ADDR,
-                                        $content,
-                                        array('Content-Type' => $content_type,
-                                              'Content-Length' => strlen($content)));
+        try {
+            $result = $this->_http->request('POST',
+                                            Horde_Service_Facebook::REST_SERVER_ADDR,
+                                            $content,
+                                            array('Content-Type' => $content_type,
+                                                  'Content-Length' => strlen($content)));
+        } catch (Exception $e) {
+            throw new Horde_Service_Facebook_Exception(sprintf(_("Upload failed: %s"), $e->getMessage()));
+        }
+
         return $result->getBody();
     }