1
0
mirror of synced 2024-11-24 22:36:06 +03:00

NotFoundException for deleted accounts

This commit is contained in:
Alex Lushpai 2020-12-29 13:46:07 +03:00 committed by GitHub
commit 1109578208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 14 deletions

View 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
{
}

View File

@ -14,6 +14,7 @@ namespace RetailCrm\Http;
use RetailCrm\Exception\CurlException; use RetailCrm\Exception\CurlException;
use RetailCrm\Exception\InvalidJsonException; use RetailCrm\Exception\InvalidJsonException;
use RetailCrm\Exception\LimitException; use RetailCrm\Exception\LimitException;
use RetailCrm\Exception\NotFoundException;
use RetailCrm\Response\ApiResponse; use RetailCrm\Response\ApiResponse;
/** /**
@ -126,20 +127,7 @@ class Client
} }
$responseBody = curl_exec($curlHandler); $responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE); $statusCode = $this->checkResponse($curlHandler, $method);
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);
}
return new ApiResponse($statusCode, $responseBody); return new ApiResponse($statusCode, $responseBody);
} }
@ -178,4 +166,38 @@ class Client
{ {
$this->options = $options; $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;
}
} }