本文整理汇总了PHP中GuzzleHttp\Psr7\Response::getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::getStatusCode方法的具体用法?PHP Response::getStatusCode怎么用?PHP Response::getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Response
的用法示例。
在下文中一共展示了Response::getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retryDecider
static function retryDecider($retries, Request $request, Response $response = null, RequestException $exception = null)
{
// Limit the number of retries to 5
if ($retries >= 5) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
}
if ($response) {
// Retry on server errors
if ($response->getStatusCode() >= 500) {
return true;
}
// Retry on rate limits
if ($response->getStatusCode() == 429) {
$retryDelay = $response->getHeaderLine('Retry-After');
if (strlen($retryDelay)) {
printf(" retry delay: %d secs\n", (int) $retryDelay);
sleep((int) $retryDelay);
return true;
}
}
}
return false;
}
示例2: setErrorResponse
/**
* @param GuzzleException $guzzleException
*/
public function setErrorResponse(GuzzleException $guzzleException)
{
$this->exception = $guzzleException;
if ($guzzleException instanceof RequestException) {
$this->response = $guzzleException->getResponse();
$this->status = $this->response->getStatusCode();
}
$this->timeResponse = microtime(true);
}
示例3: isSuccessful
/**
* Check response content is successful or not
*
* @return boolean
*/
public function isSuccessful()
{
$statusCode = $this->response->getStatusCode();
if ($statusCode == self::STATUS_CONSUME_OK || $statusCode == self::STATUS_DELETE_OK || $statusCode == self::STATUS_PRODUCE_OK) {
return true;
}
$this->errorMessage = self::$status[$statusCode];
return false;
}
示例4: deduce
/**
* @return ErrorResponse|SuccessResponse
*/
public function deduce()
{
/* @var array $response */
$response = (array) json_decode($this->response->getBody()->getContents());
if (array_key_exists('type', $response) && $response['type'] === 'error') {
return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
}
示例5: connect
/**
* Connect to server.
*/
private function connect()
{
$headers = [];
if ($this->lastId) {
$headers['Last-Event-ID'] = $this->lastId;
}
$this->response = $this->client->request('GET', $this->url, ['stream' => true, 'headers' => $headers]);
if ($this->response->getStatusCode() == 204) {
throw new RuntimeException('Server forbid connection retry by responding 204 status code.');
}
}
示例6: isJsonResponse
/**
* Check if the response given by fcm is parsable
*
* @param GuzzleResponse $response
*
* @throws InvalidRequestException
* @throws ServerResponseException
* @throws UnauthorizedRequestException
*/
private function isJsonResponse(GuzzleResponse $response)
{
if ($response->getStatusCode() == 200) {
return;
}
if ($response->getStatusCode() == 400) {
throw new InvalidRequestException($response);
}
if ($response->getStatusCode() == 401) {
throw new UnauthorizedRequestException($response);
}
throw new ServerResponseException($response);
}
示例7: search
/**
* Search book by tags like title, author, publisher etc.
*
* @param array $query
*
* @return mixed
*/
public function search(array $query)
{
$processed = $this->transformQueryParameters($query, $this->queryTransformationMap());
$query = implode(' ', $processed[1]);
foreach ($processed[0] as $key => $value) {
$query .= ' ' . $key . $value;
}
$query = $this->prepareQuery($query);
$this->response = $this->client->get($query);
if ($this->response->getStatusCode() != 200) {
$this->response = null;
}
return $this;
}
示例8: make
public static function make(Response $response)
{
$code = $response->getStatusCode();
$body = json_decode($response->getBody(), true);
if ($response->getStatusCode() == 200) {
if (!is_array($body) && is_string($body)) {
$body = ['message' => $body];
}
} else {
if (!$body['message']) {
$body = ['message' => $response->getReasonPhrase(), 'details' => $body];
}
}
return new RuleResponse($code, $body);
}
示例9: create
/**
* @param Response $response
* @return AuthorizationResponse
*/
public function create(Response $response)
{
if ($response->getStatusCode() === 200) {
return new AuthorizationResponse($response, AuthorizationResponse::AUTHORISED);
}
return new AuthorizationResponse($response, AuthorizationResponse::UNAUTHORISED);
}
示例10: setLastLogs
/**
* Set last logs
*
* @param Response|ResponseInterface $response
*/
public function setLastLogs($response)
{
$this->statusCode = $response->getStatusCode();
$content = json_decode($response->getBody()->getContents());
$this->message = isset($content->message) ? $content->message : null;
$this->errors = isset($content->errors) ? $content->errors : null;
}
示例11: getJsonResponse
public static function getJsonResponse(GuzzleHttp\Psr7\Response $res)
{
if ($res->getStatusCode() == 200) {
return json_decode($res->getBody()->getContents(), true);
}
return [];
}
示例12: updateGame
protected function updateGame(\Morpheus\SteamGame $game, \GuzzleHttp\Psr7\Response $response)
{
$body = json_decode($response->getBody());
$result = reset($body);
if ($response->getStatusCode() == 200 && isset($result->success) && $result->success === true) {
$game->steam_store_data = json_encode($result->data);
} elseif ($response->getStatusCode() !== 200) {
\Log::warning('Steam Store API call failed', ['status code' => $response->getStatusCode(), 'game' => $game]);
} elseif (!isset($result->success)) {
\Log::warning('Unexpected Steam Store API response', ['body' => $result, 'game' => $game]);
} else {
\Log::notice('Game not found in Steam Store database', ['game' => $game]);
}
$game->steam_store_updated = date('Y-m-d H:i:s');
$game->save();
}
示例13: sendOrchestratorPollRequest
/**
* Send poll request from task response
*
* If response is not from async task, return null
*
* @param Elasticsearch\Job $job
* @param \GuzzleHttp\Psr7\Response $response
* @param Encryptor $encryptor
* @param int $retriesCount
* @return \GuzzleHttp\Psr7\Response|null
*/
public function sendOrchestratorPollRequest(Elasticsearch\Job $job, \GuzzleHttp\Psr7\Response $response, Encryptor $encryptor, $retriesCount)
{
if ($response->getStatusCode() != 202) {
return null;
}
try {
$data = ResponseDecoder::decode($response);
if (!is_array($data)) {
throw new \Exception('Not json reponse');
}
if (empty($data['url'])) {
return null;
}
} catch (\Exception $e) {
//@TODO log error with debug priority
return null;
}
$timeout = 2;
try {
return $this->get($data['url'], array('config' => array('curl' => array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0)), 'headers' => array('X-StorageApi-Token' => $encryptor->decrypt($job->getToken()), 'X-KBC-RunId' => $job->getRunId(), 'X-User-Agent', KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . " - JobExecutor", 'X-Orchestrator-Poll', (int) $retriesCount), 'timeout' => 60 * $timeout));
} catch (RequestException $e) {
$handlerContext = $e->getHandlerContext();
if (is_array($handlerContext)) {
if (array_key_exists('errno', $handlerContext)) {
if ($handlerContext['errno'] == CURLE_OPERATION_TIMEOUTED) {
$this->logger->debug('curl.debug', array('handlerContext' => $e->getHandlerContext()));
throw new Exception\CurlException(sprintf('Task polling timeout after %d minutes', $timeout), $e->getRequest(), $e->getResponse(), $e);
}
}
}
throw $e;
}
}
示例14: handleError
/**
* @throws HttpException
*/
protected function handleError()
{
$body = (string) $this->response->getBody();
$code = (int) $this->response->getStatusCode();
$content = json_decode($body);
throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
}
示例15: shouldRetry
/**
* Indicates if there should be a retry or not.
*
* @param integer $retryCount The retry count.
* @param \GuzzleHttp\Psr7\Response $response The HTTP response object.
*
* @return boolean
*/
public function shouldRetry($retryCount, $response)
{
if ($retryCount >= $this->_maximumAttempts || array_search($response->getStatusCode(), $this->_retryableStatusCodes) || is_null($response)) {
return false;
} else {
return true;
}
}