Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fix json exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nesmeyanov Kirill committed Feb 6, 2017
1 parent 03a9af2 commit b7cec3d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ protected function getResponseData(ResponseInterface $response)
{
$data = json_decode((string)$response->getBody(), true);

if (json_last_error() !== JSON_ERROR_NONE) {
throw new VkException('Invalid VK response format: ' . json_last_error_msg());
}

if (!$this->passError) {
$this->checkErrors($data);
}
Expand All @@ -172,11 +168,19 @@ protected function getResponseData(ResponseInterface $response)
}

/**
* @param $data
* @param array|false $data
* @throws VkException
*/
protected function checkErrors($data)
{
if (json_last_error() !== JSON_ERROR_NONE) {
throw new VkException('Invalid VK response format: ' . json_last_error_msg());
}

if (!is_array($data)) {
throw new VkException('Invalid response format');
}

if (isset($data['error'])) {
throw self::toException($data['error']);
}
Expand Down

0 comments on commit b7cec3d

Please sign in to comment.