Skip to content

Commit

Permalink
Merge pull request #1 from forevermatt/master
Browse files Browse the repository at this point in the history
Added error handling for null response from json_decode. Improved vangrant-setup.sh.
  • Loading branch information
fillup committed Feb 10, 2014
2 parents ad24733 + 47801ef commit b84db1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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
10 changes: 9 additions & 1 deletion vagrant-setup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/bin/bash

# Create some swap space.
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1

# Add the necessary entry/entries to the hosts file.
sudo echo 127.0.0.1 apiaxle.api.local >> /etc/hosts

# Install necessary packages
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update -y
sudo apt-get install -y git python-software-properties build-essential libxml2-dev nodejs redis-server php5 php5-curl
sudo npm install -g apiaxle-base apiaxle-repl apiaxle-proxy apiaxle-api
sudo npm install -g sinon twerp apiaxle-base@1.10 apiaxle-repl@1.10 apiaxle-proxy@1.10 apiaxle-api@1.10

# Start ApiAxle processes
apiaxle-proxy -p 3000 &
Expand Down

0 comments on commit b84db1f

Please sign in to comment.