1
0
mirror of synced 2024-11-23 13:56:06 +03:00

fixed throwing NotFoundException (#98)

This commit is contained in:
azgalot 2020-12-29 14:28:36 +03:00 committed by GitHub
parent 1109578208
commit 6ed0d7eb0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,8 +126,7 @@ class Client
} }
} }
$responseBody = curl_exec($curlHandler); list($statusCode, $responseBody) = $this->checkResponse($curlHandler, $method);
$statusCode = $this->checkResponse($curlHandler, $method);
return new ApiResponse($statusCode, $responseBody); return new ApiResponse($statusCode, $responseBody);
} }
@ -171,10 +170,11 @@ class Client
* @param $curlHandler * @param $curlHandler
* @param $method * @param $method
* *
* @return mixed * @return array
*/ */
private function checkResponse($curlHandler, $method) private function checkResponse($curlHandler, $method)
{ {
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE); $statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($curlHandler, CURLINFO_CONTENT_TYPE); $contentType = curl_getinfo($curlHandler, CURLINFO_CONTENT_TYPE);
@ -183,7 +183,7 @@ class Client
} }
if ( if (
404 === $statusCode (404 === $statusCode && false !== stripos($responseBody, 'Account does not exist'))
|| ('GET' !== $method && 405 === $statusCode && false !== stripos($contentType, 'text/html')) || ('GET' !== $method && 405 === $statusCode && false !== stripos($contentType, 'text/html'))
) { ) {
throw new NotFoundException("Account does not exist"); throw new NotFoundException("Account does not exist");
@ -198,6 +198,6 @@ class Client
throw new CurlException($error, $errno); throw new CurlException($error, $errno);
} }
return $statusCode; return [$statusCode, $responseBody];
} }
} }