Skip to content

Commit

Permalink
Added check for NULL response when trying to decode the JSON data.
Browse files Browse the repository at this point in the history
  • Loading branch information
forevermatt committed Feb 10, 2014
1 parent 3ab183e commit 47801ef
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ApiAxle/Shared/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public static function callApi($apiPath, $method='GET', $data=null, $config)
$request = HttpRequest::request($url, $method, $json_data, $headers, $config);
if($request){
$results = json_decode($request);

// If unable to decode the response as JSON...
if (is_null($results)) {

// Throw an exception, suggesting to the user that the problem
// may be that ApiAxle is not running.
throw new \ErrorException('API did not return properly. ' .
'Is ApiAxle running?');
}

if($results->meta->status_code >= 200 && $results->meta->status_code < 300){
return $results->results;
} elseif($results->meta->status_code >= 300 && $results->meta->status_code < 400){
Expand Down

0 comments on commit 47801ef

Please sign in to comment.