NotFoundException for deleted accounts
This commit is contained in:
commit
1109578208
24
lib/RetailCrm/Exception/NotFoundException.php
Normal file
24
lib/RetailCrm/Exception/NotFoundException.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class LimitException
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Exception;
|
||||
|
||||
/**
|
||||
* PHP version 5.4
|
||||
*
|
||||
* Class NotFoundException
|
||||
*
|
||||
* @category RetailCrm
|
||||
* @package RetailCrm
|
||||
*/
|
||||
class NotFoundException extends \DomainException
|
||||
{
|
||||
}
|
@ -14,6 +14,7 @@ namespace RetailCrm\Http;
|
||||
use RetailCrm\Exception\CurlException;
|
||||
use RetailCrm\Exception\InvalidJsonException;
|
||||
use RetailCrm\Exception\LimitException;
|
||||
use RetailCrm\Exception\NotFoundException;
|
||||
use RetailCrm\Response\ApiResponse;
|
||||
|
||||
/**
|
||||
@ -126,20 +127,7 @@ class Client
|
||||
}
|
||||
|
||||
$responseBody = curl_exec($curlHandler);
|
||||
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($statusCode == 503) {
|
||||
throw new LimitException("Service temporary unavailable");
|
||||
}
|
||||
|
||||
$errno = curl_errno($curlHandler);
|
||||
$error = curl_error($curlHandler);
|
||||
|
||||
curl_close($curlHandler);
|
||||
|
||||
if ($errno) {
|
||||
throw new CurlException($error, $errno);
|
||||
}
|
||||
$statusCode = $this->checkResponse($curlHandler, $method);
|
||||
|
||||
return new ApiResponse($statusCode, $responseBody);
|
||||
}
|
||||
@ -178,4 +166,38 @@ class Client
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $curlHandler
|
||||
* @param $method
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function checkResponse($curlHandler, $method)
|
||||
{
|
||||
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
|
||||
$contentType = curl_getinfo($curlHandler, CURLINFO_CONTENT_TYPE);
|
||||
|
||||
if (503 === $statusCode) {
|
||||
throw new LimitException("Service temporary unavailable");
|
||||
}
|
||||
|
||||
if (
|
||||
404 === $statusCode
|
||||
|| ('GET' !== $method && 405 === $statusCode && false !== stripos($contentType, 'text/html'))
|
||||
) {
|
||||
throw new NotFoundException("Account does not exist");
|
||||
}
|
||||
|
||||
$errno = curl_errno($curlHandler);
|
||||
$error = curl_error($curlHandler);
|
||||
|
||||
curl_close($curlHandler);
|
||||
|
||||
if ($errno) {
|
||||
throw new CurlException($error, $errno);
|
||||
}
|
||||
|
||||
return $statusCode;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user