1
0
mirror of synced 2024-11-22 05:16:07 +03:00

Merge pull request #21 from gwinn/master

make retry local, remove redundant error types
This commit is contained in:
Alex Lushpai 2016-07-26 15:42:16 +04:00 committed by GitHub
commit 3dc1fbb7a9

View File

@ -36,7 +36,6 @@ class Client
protected $url; protected $url;
protected $defaultParameters; protected $defaultParameters;
protected $retry;
/** /**
* Client constructor. * Client constructor.
@ -62,10 +61,7 @@ class Client
CURLE_COULDNT_RESOLVE_HOST, CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT, CURLE_COULDNT_CONNECT,
CURLE_OPERATION_TIMEOUTED, CURLE_OPERATION_TIMEOUTED,
CURLE_HTTP_POST_ERROR, CURLE_SSL_CONNECT_ERROR
CURLE_SSL_CONNECT_ERROR,
CURLE_SEND_ERROR,
CURLE_RECV_ERROR
); );
} }
@ -90,6 +86,7 @@ class Client
array $parameters = array() array $parameters = array()
) { ) {
$allowedMethods = array(self::METHOD_GET, self::METHOD_POST); $allowedMethods = array(self::METHOD_GET, self::METHOD_POST);
$retry = 0;
if (!in_array($method, $allowedMethods, false)) { if (!in_array($method, $allowedMethods, false)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
@ -133,28 +130,19 @@ class Client
if ($errno if ($errno
&& in_array($errno, $this->curlErrors, false) && in_array($errno, $this->curlErrors, false)
&& $this->retry < 3 && $retry < 3
) { ) {
$errno = null; $errno = null;
$error = null; $error = null;
++$this->retry; $retry++;
$this->makeRequest($path, $method, $parameters); $this->makeRequest($path, $method, $parameters);
} }
if ($errno) { if ($errno) {
$retry = 0;
throw new CurlException($error, $errno); throw new CurlException($error, $errno);
} }
return new ApiResponse($statusCode, $responseBody); return new ApiResponse($statusCode, $responseBody);
} }
/**
* Retry connect
*
* @return int
*/
public function getRetry()
{
return $this->retry;
}
} }