Skip to content

Commit

Permalink
Merge pull request #996 from pantheon-systems/fix/api_server_error_no…
Browse files Browse the repository at this point in the history
…nzero_exit

Ensured that API and server errors exit with non-zero status
  • Loading branch information
TeslaDethray committed Mar 16, 2016
2 parents a826bba + d8b18c8 commit c1121cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 8 additions & 19 deletions php/Terminus/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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),
Expand All @@ -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;
}
Expand Down

0 comments on commit c1121cf

Please sign in to comment.