From a9bcbc9fb5b97f7af0cddc74fba86e06944d0be1 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 16 Sep 2009 17:34:58 -0400 Subject: [PATCH] No longer have to fake a JSON response from an exception now that 4xx and 5xx responses do not throw one. --- .../lib/Horde/Service/Twitter/Request/Basic.php | 16 ++++++++-------- .../lib/Horde/Service/Twitter/Request/Oauth.php | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) 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(); } -- 2.11.0