diff --git a/providers/Twitter/Provider.php b/providers/Twitter/Provider.php index 90b93e15e..ef832b409 100644 --- a/providers/Twitter/Provider.php +++ b/providers/Twitter/Provider.php @@ -6,6 +6,7 @@ namespace SocialConnect\Twitter; +use SocialConnect\Auth\Exception\InvalidResponse; use SocialConnect\Auth\Provider\OAuth1\AccessToken; use SocialConnect\Common\Entity\User; use SocialConnect\Common\Http\Client\Client; @@ -55,17 +56,27 @@ public function getIdentity(AccessToken $accessToken) $this->requestTokenHeaders ); - if ($response->getStatusCode() == 200) { - $result = $response->json(); + if (!$response->isSuccess()) { + throw new InvalidResponse( + 'API response with error code', + $response + ); + } - $hydrator = new ObjectMap(array( - 'id' => 'id', - 'name' => 'fullname', - 'screen_name' => 'username' - )); - return $hydrator->hydrate(new User(), $result[0]); + $result = $response->json(); + if (!$result) { + throw new InvalidResponse( + 'API response is not a valid JSON object', + $response->getBody() + ); } - return false; + $hydrator = new ObjectMap(array( + 'id' => 'id', + 'name' => 'fullname', + 'screen_name' => 'username' + )); + + return $hydrator->hydrate(new User(), $result[0]); } }