From d8b18c896ff45625120db01bce094f8c036051b3 Mon Sep 17 00:00:00 2001 From: Sara McCutcheon Date: Wed, 16 Mar 2016 16:08:40 -0700 Subject: [PATCH] Ensured that API and server errors exit with non-zero status --- CHANGELOG.md | 1 + php/Terminus/Request.php | 27 ++++++++------------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 172d4613a..79b345ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to this project starting with the 0.6.0 release will be docu - Fixed unidentified index email warning which appeared when logging in via saved machine token by email. (#983) - Prevented long loop of configurator loadings. (#988) - Fixed auth status check before running `CommandWithSSH` descendant commands (`drush`, `wp`). (#986) +- Ensured that API and server errors exit with non-zero status. (#996) ## [0.10.6] - 2016-03-07 ### Changed diff --git a/php/Terminus/Request.php b/php/Terminus/Request.php index 0530098ec..b09849ae1 100755 --- a/php/Terminus/Request.php +++ b/php/Terminus/Request.php @@ -21,21 +21,6 @@ class Request { - /** - * @var Logger - */ - private $logger; - - /** - * Object constructor. Saves the logger as a class property. - * - * @return Request - */ - public function __construct() { - $runner = new Runner(); - $this->logger = $runner->getLogger(); - } - /** * Download file from target URL * @@ -146,12 +131,12 @@ public function request($path, $arg_options = []) { } try { - $this->logger->debug('URL: {url}', compact('url')); $response = $this->send($url, $options['method'], $options); } catch (\GuzzleHttp\Exception\BadResponseException $e) { throw new TerminusException( 'API Request Error: {msg}', - ['msg' => $e->getMessage(),] + ['msg' => $e->getMessage(),], + 1 ); } @@ -200,7 +185,7 @@ private function send($uri, $method, array $arg_params = []) { ); unset($params['cookies']); - $this->logger->debug( + Runner::getLogger()->debug( "#### REQUEST ####\nParams: {params}\nURI: {uri}\nMethod: {method}", [ 'params' => json_encode($params), @@ -213,7 +198,11 @@ private function send($uri, $method, array $arg_params = []) { error_reporting(E_ALL ^ E_WARNING); $request = new HttpRequest(ucwords($method), $uri, $params); error_reporting(E_ALL); - $response = $client->send($request, $params); + try { + $response = $client->send($request, $params); + } catch (\Exception $e) { + throw new TerminusException($e->getMessage(), [], 1); + } return $response; }