Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.

Commit

Permalink
Throw exception when $result is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklul committed May 8, 2018
1 parent 9da29cf commit 38c3711
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/E621.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use jacklul\E621API\Entity\UserRecord;
use jacklul\E621API\Entity\Wiki;
use jacklul\E621API\Entity\WikiHistory;
use RuntimeException;

/**
* Simple object-oriented e621 API wrapper
Expand Down Expand Up @@ -813,6 +814,7 @@ public function __call($action, array $data = [])
*
* @return string
* @throws InvalidArgumentException
* @throws RuntimeException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function request($path = 'post/index.json', array $data = null, $method = 'GET', $class = null)
Expand All @@ -836,6 +838,10 @@ private function request($path = 'post/index.json', array $data = null, $method
$response = $this->client->request($method, $path, $options);
$raw_result = (string)$response->getBody();
$result = json_decode($raw_result, true);

if (!is_array($result)) {
throw new RuntimeException('Result is not an array!');
}
} catch (RequestException $e) {
$this->debugLog($e);
$result = ($e->getResponse()) ? (string)$e->getResponse()->getBody() : 'Empty response / Request timed out';
Expand Down

0 comments on commit 38c3711

Please sign in to comment.