From: Michael J. Rubinsky Date: Wed, 16 Sep 2009 21:34:58 +0000 (-0400) Subject: No longer have to fake a JSON response from an exception now that 4xx and 5xx X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a9bcbc9fb5b97f7af0cddc74fba86e06944d0be1;p=horde.git No longer have to fake a JSON response from an exception now that 4xx and 5xx responses do not throw one. --- 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 5654fd39f..f085172d6 100644 --- a/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php +++ b/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Basic.php @@ -31,13 +31,13 @@ class Horde_Service_Twitter_Request_Basic extends Horde_Service_Twitter_Request 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() . '"}'; + throw new Horde_Service_Twitter_Exception($e); } $body = $response->getBody(); + if ($response->code >= 400 && $response->code <= 500) { + throw new Horde_Service_Twitter_Exception($body); + } if (!empty($cache)) { $cache->set($key, $body); } @@ -51,12 +51,12 @@ class Horde_Service_Twitter_Request_Basic extends Horde_Service_Twitter_Request 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() . '"}'; + throw new Horde_Service_Twitter_Exception($e); } + if ($response->code >= 400 && $response->code <= 500) { + throw new Horde_Service_Twitter_Exception($body); + } return $response->getBody(); } diff --git a/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Oauth.php b/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Oauth.php index a48cd7e96..87702f939 100644 --- a/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Oauth.php +++ b/framework/Service_Twitter/lib/Horde/Service/Twitter/Request/Oauth.php @@ -35,13 +35,13 @@ class Horde_Service_Twitter_Request_Oauth extends Horde_Service_Twitter_Request try { $response = $client->get($url, array('Authorization' => $request->buildAuthorizationHeader('Twitter API'))); } 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() . '"}'; + throw new Horde_Service_Twitter_Exception($e); } $body = $response->getBody(); + if ($response->code >= 400 && $response->code <= 500) { + throw new Horde_Service_Twitter_Exception($body); + } if (!empty($cache)) { $cache->set($key, $body); } @@ -65,12 +65,12 @@ class Horde_Service_Twitter_Request_Oauth extends Horde_Service_Twitter_Request try { $response = $client->post($url, $params, array('Authorization' => $request->buildAuthorizationHeader('Twitter API'))); } 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() . '"}'; + throw new Horde_Service_Twitter_Exception($e); } + if ($response->code >= 400 && $response->code <= 500) { + throw new Horde_Service_Twitter_Exception($body); + } return $response->getBody(); }