public function testErrorStatusCanBeCheckedWhenAnErrorResponseIsReturned()
 {
     $app = new FacebookApp('123', 'foo_secret');
     $graphResponse = '{"error":{"message":"Foo error.","type":"OAuthException","code":190,"error_subcode":463}}';
     $response = new FacebookResponse($app, 401, [], $graphResponse);
     $exception = $response->getThrownException();
     $this->assertTrue($response->isError(), 'Expected Response to return an error.');
     $this->assertInstanceOf('Facebook\\Exceptions\\FacebookResponseException', $exception);
 }
 /**
  * Makes the request to Graph and returns the result.
  *
  * @param FacebookRequest $request
  *
  * @return FacebookResponse
  *
  * @throws FacebookSDKException
  */
 public function sendRequest(FacebookRequest $request)
 {
     if (get_class($request) === 'FacebookRequest') {
         $request->validateAccessToken();
     }
     $url = $this->getBaseGraphUrl() . $request->getUrl();
     $method = $request->getMethod();
     $params = $request->getPostParams();
     $headers = $request->getHeaders();
     // Should throw `FacebookSDKException` exception on HTTP client error.
     // Don't catch to allow it to bubble up.
     $response = $this->httpClientHandler->send($url, $method, $params, $headers);
     static::$requestCount++;
     $httpResponseCode = $this->httpClientHandler->getResponseHttpStatusCode();
     $httpResponseHeaders = $this->httpClientHandler->getResponseHeaders();
     $accessToken = $request->getAccessToken();
     $app = $request->getApp();
     $returnResponse = new FacebookResponse($app, $httpResponseCode, $httpResponseHeaders, $response, $accessToken);
     if ($returnResponse->isError()) {
         throw $returnResponse->getThrownException();
     }
     return $returnResponse;
 }