From 89ecd56299f96d72ad63ba624bde69ff1d4fa6a2 Mon Sep 17 00:00:00 2001 From: Moritz Kornher Date: Mon, 29 May 2017 18:42:07 +1200 Subject: [PATCH 1/3] Fix for reading error message from response --- lib/ServerPilot.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ServerPilot.php b/lib/ServerPilot.php index aff09ad..72a228c 100644 --- a/lib/ServerPilot.php +++ b/lib/ServerPilot.php @@ -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 @@ -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( $response, 'error' ) && property_exists( $response, 'message' ) ) + throw new ServerPilotException($data->error->message, $http_status); + // No error as provided, pick a default switch( $http_status ) { From 274f69794a95697edc2e41034ab7c33e0f8c6cd2 Mon Sep 17 00:00:00 2001 From: Moritz Kornher Date: Tue, 30 May 2017 09:43:03 +1200 Subject: [PATCH 2/3] Fix checking for response string instead of object. --- lib/ServerPilot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ServerPilot.php b/lib/ServerPilot.php index 72a228c..58e7bf1 100644 --- a/lib/ServerPilot.php +++ b/lib/ServerPilot.php @@ -424,7 +424,7 @@ private function _send_request( $url_segs, $params = array(), $http_method = 'ge $data = json_decode( $response ); // The error was provided by serverpilot - if( property_exists( $response, 'error' ) && property_exists( $response, 'message' ) ) + if( property_exists( $data, 'error' ) && property_exists( $data, 'message' ) ) throw new ServerPilotException($data->error->message, $http_status); // No error as provided, pick a default From fa3365d9ed8c711c6c71059bf3a50ce73a67a2a6 Mon Sep 17 00:00:00 2001 From: Moritz Kornher Date: Tue, 30 May 2017 13:58:15 +1200 Subject: [PATCH 3/3] And forgot to use the error property on second check --- lib/ServerPilot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ServerPilot.php b/lib/ServerPilot.php index 58e7bf1..023c3e6 100644 --- a/lib/ServerPilot.php +++ b/lib/ServerPilot.php @@ -424,7 +424,7 @@ private function _send_request( $url_segs, $params = array(), $http_method = 'ge $data = json_decode( $response ); // The error was provided by serverpilot - if( property_exists( $data, 'error' ) && property_exists( $data, 'message' ) ) + 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