Skip to content

Commit

Permalink
Add error handling for "GuzzleHttp\Exception\ClientException"
Browse files Browse the repository at this point in the history
  • Loading branch information
nilov committed Feb 4, 2017
1 parent d383ca3 commit 2dc5fa3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions CmsRestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Glavweb\CmsRestClient;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

/**
* Class CmsRestClient
Expand Down Expand Up @@ -50,9 +51,9 @@ class CmsRestClient
* @var string
*/
private static $token = false;

/**
* CmsRestClient constructor.
* ContentBlockService constructor.
*
* @param Client $guzzle
* @param string $apiBaseUrl
Expand Down Expand Up @@ -198,13 +199,18 @@ public function validateToken($token, $cash = true)
*/
public function doValidateToken($token)
{
$response = $this->guzzle->request('GET', $this->url('validate-token'), [
'headers' => [
'Token' => $token
],
]);
try {
$response = $this->guzzle->request('GET', $this->url('validate-token'), [
'headers' => [
'Token' => $token
],
]);

return $response->getStatusCode() == 200;
return $response->getStatusCode() == 200;

} catch (ClientException $e) {
return false;
}
}

/**
Expand Down

0 comments on commit 2dc5fa3

Please sign in to comment.