Skip to content

Commit e6d64be

Browse files
authored
fix: exception option fallback is http_errors on guzzle 6 and 7 (#1966)
1 parent d0dcc70 commit e6d64be

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/Google/AuthHandler/Guzzle6AuthHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function createAuthHttp(ClientInterface $http)
9797
return new Client(
9898
[
9999
'base_uri' => $http->getConfig('base_uri'),
100-
'exceptions' => true,
100+
'http_errors' => true,
101101
'verify' => $http->getConfig('verify'),
102102
'proxy' => $http->getConfig('proxy'),
103103
]

src/Google/Client.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,10 @@ protected function createDefaultHttpClient()
11481148
$guzzleVersion = (int)substr(ClientInterface::VERSION, 0, 1);
11491149
}
11501150

1151-
$options = ['exceptions' => false];
11521151
if (5 === $guzzleVersion) {
11531152
$options = [
11541153
'base_url' => $this->config['base_path'],
1155-
'defaults' => $options,
1154+
'defaults' => ['exceptions' => false],
11561155
];
11571156
if ($this->isAppEngine()) {
11581157
// set StreamHandler on AppEngine by default
@@ -1161,7 +1160,10 @@ protected function createDefaultHttpClient()
11611160
}
11621161
} elseif (6 === $guzzleVersion || 7 === $guzzleVersion) {
11631162
// guzzle 6 or 7
1164-
$options['base_uri'] = $this->config['base_path'];
1163+
$options = [
1164+
'base_uri' => $this->config['base_path'],
1165+
'http_errors' => false,
1166+
];
11651167
} else {
11661168
throw new LogicException('Could not find supported version of Guzzle.');
11671169
}

tests/Google/ClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ public function testSettersGetters()
301301
$this->assertEquals($token, $client->getAccessToken());
302302
}
303303

304+
public function testDefaultConfigOptions()
305+
{
306+
$client = new Google_Client();
307+
if ($this->isGuzzle6() || $this->isGuzzle7()) {
308+
$this->assertArrayHasKey('http_errors', $client->getHttpClient()->getConfig());
309+
$this->assertArrayNotHasKey('exceptions', $client->getHttpClient()->getConfig());
310+
$this->assertFalse($client->getHttpClient()->getConfig()['http_errors']);
311+
}
312+
if ($this->isGuzzle5()) {
313+
$this->assertArrayHasKey('exceptions', $client->getHttpClient()->getDefaultOption());
314+
$this->assertArrayNotHasKey('http_errors', $client->getHttpClient()->getDefaultOption());
315+
$this->assertFalse($client->getHttpClient()->getDefaultOption()['exceptions']);
316+
}
317+
}
318+
304319
public function testAppEngineStreamHandlerConfig()
305320
{
306321
$this->onlyGuzzle5();

0 commit comments

Comments
 (0)