From: Michael J. Rubinsky Date: Wed, 29 Jul 2009 00:25:51 +0000 (-0400) Subject: Catch exceptions from Horde_Http_Client X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=05cd04321718788ffc5ce78b8390a667057d5f01;p=horde.git Catch exceptions from Horde_Http_Client --- diff --git a/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php b/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php index 6b856c4e2..5654fd39f 100644 --- a/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php +++ b/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php @@ -28,7 +28,14 @@ class Horde_Service_Twitter_Request_Basic extends Horde_Service_Twitter_Request return $results; } $client = new Horde_Http_Client(); - $response = $client->get($url, array('Authorization' => $this->_twitter->auth->buildAuthorizationHeader())); + try { + $response = $client->get($url, array('Authorization' => $this->_twitter->auth->buildAuthorizationHeader())); + } catch (Horde_Http_Client_Exception $e) { + // Currently we can't obtain any information regarding the resposne + // when a 4xx/5xx response is rec'd due to fopen() failing. + // For now, fake it and return the error from the exception. + return '{"request":"' . $url . '", "error:", "' . $e->getMessage() . '"}'; + } $body = $response->getBody(); if (!empty($cache)) { @@ -41,7 +48,14 @@ class Horde_Service_Twitter_Request_Basic extends Horde_Service_Twitter_Request public function post($url, $params = array()) { $client = new Horde_Http_Client(); - $response = $client->post($url, $params, array('Authorization' => $this->_twitter->auth->buildAuthorizationHeader())); + try { + $response = $client->post($url, $params, array('Authorization' => $this->_twitter->auth->buildAuthorizationHeader())); + } catch (Horde_Http_Client_Exception $e) { + // Currently we can't obtain any information regarding the resposne + // when a 4xx/5xx response is rec'd due to fopen() failing. + // For now, fake it and return the error from the exception. + return '{"request":"' . $url . '", "error:", "' . $e->getMessage() . '"}'; + } return $response->getBody(); }