Skip to content

Commit 31a3bda

Browse files
Merge pull request #13 from stackkit/feature/retry-failed-google-api-requests
Retry failed Google API requests
2 parents c1b4197 + cd47b8b commit 31a3bda

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/OpenIdVerificator.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Firebase\JWT\JWT;
77
use Firebase\JWT\SignatureInvalidException;
88
use GuzzleHttp\Client;
9+
use GuzzleHttp\Exception\ServerException;
910
use Illuminate\Support\Arr;
1011
use Illuminate\Support\Facades\Cache;
1112
use phpseclib\Crypt\RSA;
@@ -105,7 +106,23 @@ public function getKidFromOpenIdToken($openIdToken)
105106

106107
private function callApiAndReturnValue($url, $value)
107108
{
108-
$response = $this->guzzle->get($url);
109+
$attempts = 0;
110+
111+
while (true) {
112+
try {
113+
$response = $this->guzzle->get($url);
114+
115+
break;
116+
} catch (ServerException $e) {
117+
$attempts++;
118+
119+
if ($attempts >= 3) {
120+
throw $e;
121+
}
122+
123+
sleep(1);
124+
}
125+
}
109126

110127
$data = json_decode($response->getBody(), true);
111128

0 commit comments

Comments
 (0)