From 1826dd57d6dd3fa78a6aef7ee4385a9fbac788d0 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Tue, 27 Feb 2018 12:00:09 +0300 Subject: [PATCH] Add LimitException (#61) Add LimitException class to determine if the query limit is exceeded --- lib/RetailCrm/Exception/LimitException.php | 30 +++++++++++++++++++ lib/RetailCrm/Http/Client.php | 6 ++++ .../Version5/ApiClientCustomersTest.php | 2 +- .../Version5/ApiClientDeliveryTest.php | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 lib/RetailCrm/Exception/LimitException.php diff --git a/lib/RetailCrm/Exception/LimitException.php b/lib/RetailCrm/Exception/LimitException.php new file mode 100644 index 0000000..31caf1a --- /dev/null +++ b/lib/RetailCrm/Exception/LimitException.php @@ -0,0 +1,30 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ + +namespace RetailCrm\Exception; + +/** + * PHP version 5.4 + * + * Class LimitException + * + * @category RetailCrm + * @package RetailCrm + * @author RetailCrm + * @license https://opensource.org/licenses/MIT MIT License + * @link http://www.retailcrm.ru/docs/Developers/ApiVersion5 + */ +class LimitException extends \DomainException +{ +} diff --git a/lib/RetailCrm/Http/Client.php b/lib/RetailCrm/Http/Client.php index 419dd00..001f8b0 100755 --- a/lib/RetailCrm/Http/Client.php +++ b/lib/RetailCrm/Http/Client.php @@ -16,6 +16,7 @@ namespace RetailCrm\Http; use RetailCrm\Exception\CurlException; use RetailCrm\Exception\InvalidJsonException; +use RetailCrm\Exception\LimitException; use RetailCrm\Response\ApiResponse; /** @@ -116,6 +117,11 @@ class Client $responseBody = curl_exec($curlHandler); $statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE); + + if ($statusCode == 503) { + throw new LimitException("Service temporary unavalable"); + } + $errno = curl_errno($curlHandler); $error = curl_error($curlHandler); diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientCustomersTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientCustomersTest.php index 729fd78..17aea39 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientCustomersTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientCustomersTest.php @@ -407,7 +407,7 @@ class ApiClientCustomersTest extends TestCase */ public function testCustomersNotesDelete() { - self::markTestSkipped('Sould be fixed.'); + self::markTestSkipped('Should be fixed.'); $client = static::getApiClient(); diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientDeliveryTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientDeliveryTest.php index 0ec22cb..032f81f 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientDeliveryTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientDeliveryTest.php @@ -55,7 +55,7 @@ class ApiClientDeliveryTest extends TestCase */ public function testDeliveryShipments() { - self::markTestSkipped('Sould be fixed.'); + self::markTestSkipped('Should be fixed.'); $client = static::getApiClient();