public function testErrorStatusCanBeCheckedWhenAnErrorResponseIsReturned() { $graphResponse = '{"error":{"message":"Foo error.","type":"OAuthException","code":190,"error_subcode":463}}'; $response = new FacebookResponse($this->request, $graphResponse, 401); $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(); } list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); // Since file uploads can take a while, we need to give more time for uploads $timeOut = static::DEFAULT_REQUEST_TIMEOUT; if ($request->containsFileUploads()) { $timeOut = static::DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT; } elseif ($request->containsVideoUploads()) { $timeOut = static::DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT; } // Should throw `FacebookSDKException` exception on HTTP client error. // Don't catch to allow it to bubble up. $rawResponse = $this->httpClientHandler->send($url, $method, $body, $headers, $timeOut); static::$requestCount++; $returnResponse = new FacebookResponse($request, $rawResponse->getBody(), $rawResponse->getHttpResponseCode(), $rawResponse->getHeaders()); if ($returnResponse->isError()) { throw $returnResponse->getThrownException(); } return $returnResponse; }