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

Commit

Permalink
Merge pull request #16 from mrgrain/fix-issue-15-wrong-error-message-…
Browse files Browse the repository at this point in the history
…in-exception

Fix for reading error message from response
  • Loading branch information
daverogers authored Jun 1, 2017
2 parents 9e49e6a + fa3365d commit a5f846c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/ServerPilot.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public function database_update( $id, $userid, $password ) {
public function action_info( $id ) {
return $this->_send_request( "actions/$id" );
}

/**
* @param string $url_segs
* @param array array $params
Expand Down Expand Up @@ -419,14 +419,14 @@ private function _send_request( $url_segs, $params = array(), $http_method = 'ge
else
return $response;
}
// Some error occured

// Some error occurred
$data = json_decode( $response );

// The error was provided by serverpilot
if( property_exists( $response, 'error' ) )
throw new ServerPilotException($data->error, $http_status);
if( property_exists( $data, 'error' ) && property_exists( $data->error, 'message' ) )
throw new ServerPilotException($data->error->message, $http_status);

// No error as provided, pick a default
switch( $http_status )
{
Expand Down

0 comments on commit a5f846c

Please sign in to comment.