From 2dc5fa34402b424628ef6817144e90348d425d56 Mon Sep 17 00:00:00 2001 From: nilov Date: Sat, 4 Feb 2017 11:47:20 +0700 Subject: [PATCH] Add error handling for "GuzzleHttp\Exception\ClientException" --- CmsRestClient.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CmsRestClient.php b/CmsRestClient.php index c31e9c1..c5f32a7 100644 --- a/CmsRestClient.php +++ b/CmsRestClient.php @@ -12,6 +12,7 @@ namespace Glavweb\CmsRestClient; use GuzzleHttp\Client; +use GuzzleHttp\Exception\ClientException; /** * Class CmsRestClient @@ -50,9 +51,9 @@ class CmsRestClient * @var string */ private static $token = false; - + /** - * CmsRestClient constructor. + * ContentBlockService constructor. * * @param Client $guzzle * @param string $apiBaseUrl @@ -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; + } } /**