From 60b423cef70df28344189067ef30b56c5874564b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= <mxr576@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:49:04 +0100 Subject: [PATCH] Change exceptions used to catch failed GCE authentication (#334) --- src/HttpClient/Plugin/Authentication/GceServiceAccount.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/HttpClient/Plugin/Authentication/GceServiceAccount.php b/src/HttpClient/Plugin/Authentication/GceServiceAccount.php index f23c9044..f932067d 100644 --- a/src/HttpClient/Plugin/Authentication/GceServiceAccount.php +++ b/src/HttpClient/Plugin/Authentication/GceServiceAccount.php @@ -21,8 +21,9 @@ use Apigee\Edge\Client; use Apigee\Edge\ClientInterface; use Apigee\Edge\Exception\ApigeeOnGcpOauth2AuthenticationException; -use Http\Client\Exception; use Http\Message\Authentication\Header; +use Psr\Http\Client\ClientExceptionInterface; +use Psr\Http\Client\NetworkExceptionInterface; /** * GCE Service Account authentication plugin for authenticating to Google @@ -61,7 +62,7 @@ public function isAvailable(): bool $this->authClient()->get(''); return true; - } catch (Exception $e) { + } catch (NetworkExceptionInterface $e) { return false; } } @@ -85,7 +86,7 @@ protected function getAccessToken(): void $response = $this->authClient()->get(''); $decoded_token = json_decode((string) $response->getBody(), true); $this->tokenStorage->saveToken($decoded_token); - } catch (Exception $e) { + } catch (ClientExceptionInterface $e) { throw new ApigeeOnGcpOauth2AuthenticationException($e->getMessage(), $e->getCode(), $e); } }