public function testOtherException() { $params = ['error' => ['code' => 42, 'message' => 'ship love', 'error_subcode' => 0, 'type' => 'feature']]; $response = new FacebookResponse($this->request, json_encode($params), 200); $exception = FacebookResponseException::create($response); $this->assertInstanceOf('Facebook\\Exceptions\\FacebookOtherException', $exception->getPrevious()); $this->assertEquals(42, $exception->getCode()); $this->assertEquals(0, $exception->getSubErrorCode()); $this->assertEquals('feature', $exception->getErrorType()); $this->assertEquals('ship love', $exception->getMessage()); $this->assertEquals(json_encode($params), $exception->getRawResponse()); $this->assertEquals(200, $exception->getHttpStatusCode()); }
/** * Instantiates an exception to be thrown later. */ public function makeException() { $this->thrownException = FacebookResponseException::create($this); }
/** * execute - Makes the request to Facebook and returns the result. * * @return FacebookResponse * * @throws FacebookSDKException * @throws FacebookResponseException */ public function execute() { $url = $this->getRequestURL(); $params = $this->getParameters(); if ($this->method === "GET") { $url = self::appendParamsToUrl($url, $params); $params = array(); } $connection = self::getHttpClientHandler(); $connection->addRequestHeader('User-Agent', 'fb-php-' . self::VERSION); $connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings. // ETag if (isset($this->etag)) { $connection->addRequestHeader('If-None-Match', $this->etag); } // Should throw `FacebookSDKException` exception on HTTP client error. // Don't catch to allow it to bubble up. $result = $connection->send($url, $this->method, $params); static::$requestCount++; $etagHit = 304 == $connection->getResponseHttpStatusCode(); $headers = $connection->getResponseHeaders(); $etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null; $decodedResult = json_decode($result); if ($decodedResult === null) { $out = array(); parse_str($result, $out); return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived); } if (isset($decodedResult->error)) { throw FacebookResponseException::create($result, $decodedResult->error, $connection->getResponseHttpStatusCode()); } return new FacebookResponse($this, $decodedResult, $result, $etagHit, $etagReceived); }
public function testOtherException() { $params = ['error' => ['code' => 42, 'message' => 'ship love', 'error_subcode' => 0, 'type' => 'feature']]; $json = json_encode($params); $exception = FacebookResponseException::create($json, $params, 200); $this->assertTrue($exception instanceof FacebookOtherException); $this->assertEquals(42, $exception->getCode()); $this->assertEquals(0, $exception->getSubErrorCode()); $this->assertEquals('feature', $exception->getErrorType()); $this->assertEquals('ship love', $exception->getMessage()); $this->assertEquals($json, $exception->getRawResponse()); $this->assertEquals(200, $exception->getHttpStatusCode()); }
/** * Request a code from a long lived access token. * * @param array $params * @param string|null $appId * @param string|null $appSecret * * @return string * * @throws FacebookResponseException */ public static function requestCode(array $params, $appId = null, $appSecret = null) { $response = static::request('/oauth/client_code', $params, $appId, $appSecret); $data = $response->getResponse(); if (isset($data->code)) { return (string) $data->code; } throw FacebookResponseException::create($response->getRawResponse(), $data, 401); }
/** * Instantiates an exception to be thrown later. */ public function makeException() { $this->thrownException = FacebookResponseException::create($this->body, $this->decodedBody, $this->httpStatusCode); }