From c9841b4ac42194b1db2be967838034d807bcd071 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 4 Mar 2009 20:32:04 -0500 Subject: [PATCH] Catch exceptions from the http client and rethrow them as Horde_Service_Facebook_Exception if needed. --- .../lib/Horde/Service/Facebook/Request.php | 16 +++++++++++++- .../lib/Horde/Service/Facebook/UploadRequest.php | 25 ++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php index c4445bee0..fffeb1f7c 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Request.php @@ -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(); } diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/UploadRequest.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/UploadRequest.php index 32d9820f0..4dbe225be 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook/UploadRequest.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/UploadRequest.php @@ -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(); } -- 2.11.0