Skip to content

Commit

Permalink
Handle Guzzle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zeliard91 committed Apr 29, 2017
1 parent caaaf87 commit 22abfef
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Service/GoogleTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,19 @@ private function call($fonction, $params = array(), $method = 'GET')
$clientParams['headers']['Content-Type'] = 'application/x-www-form-urlencoded';
}

$response = $this->client->request($method, self::URL.$fonction, $clientParams);
try {
$response = $this->client->request($method, self::URL.$fonction, $clientParams);
} catch (\GuzzleHttp\Exception\RequestException $e) {
$this->logger->error('REST Exception', ['e' => $e, 'url' => self::URL.$fonction, 'params' => $clientParams]);
$message = $e->getResponse()->getReasonPhrase();

$json = json_decode($e->getResponse()->getBody());
if (null !== $json && isset($json->error, $json->error->message)) {
$message = $json->error->message;
}

throw new \Exception($message, $e->getCode());
}

return $this->handlingCallResponse($response);
}
Expand Down

0 comments on commit 22abfef

Please sign in to comment.