Skip to content

Commit 0f04cdd

Browse files
committed
Do not retry on 401 and its test
1 parent 2ea1e70 commit 0f04cdd

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Google/RestApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ protected function decideRetry(int $retries, int $maxRetries, ?ResponseInterface
319319
if ($statusCode >= 200 && $statusCode < 300) {
320320
return false;
321321
}
322-
if ($statusCode === 400) {
322+
if ($statusCode === 400 || $statusCode === 401) {
323323
return false;
324324
}
325325
if ($statusCode === 403) {

tests/RestApiTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,29 @@ public function testRetries(): void
150150
}
151151
}
152152

153+
public function testDoNotRetryOnWrongCredentials(): void
154+
{
155+
$testHandler = new TestHandler();
156+
$logger = new Logger('Google Rest API tests');
157+
$logger->pushHandler($testHandler);
158+
$api = new RestApi(
159+
$this->getEnv('CLIENT_ID'),
160+
$this->getEnv('CLIENT_SECRET') . 'invalid',
161+
'',
162+
$this->getEnv('REFRESH_TOKEN'),
163+
$logger
164+
);
165+
166+
try {
167+
$api->refreshToken();
168+
} catch (ClientException $e) {
169+
$this->assertStringContainsString('401 Unauthorized', $e->getMessage());
170+
}
171+
172+
$this->assertEmpty($testHandler->getRecords());
173+
174+
}
175+
153176
protected function getEnv(string $name): string
154177
{
155178
$value = getenv($name);

0 commit comments

Comments
 (0)