Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/LaunchDarkly/Impl/Integrations/GuzzleFeatureRequester.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace LaunchDarkly\Impl\Integrations;

use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\HandlerStack;
Expand Down Expand Up @@ -75,6 +76,9 @@ public function getFeature(string $key): ?FeatureFlag
$this->handleUnexpectedStatus($code, "GuzzleFeatureRequester::get");
}
return null;
} catch (Exception $e) {
$this->_logger->error("GuzzleFeatureRequester::get encountered an exception retrieving flag key {$key}: " . $e->getMessage());
return null;
}
}

Expand All @@ -99,6 +103,9 @@ public function getSegment(string $key): ?Segment
$this->handleUnexpectedStatus($code, "GuzzleFeatureRequester::get");
}
return null;
} catch (Exception $e) {
$this->_logger->error("GuzzleFeatureRequester::get encountered an exception retrieving segment key {$key}: " . $e->getMessage());
return null;
}
}

Expand All @@ -117,6 +124,9 @@ public function getAllFeatures(): ?array
/** @psalm-suppress PossiblyNullReference (resolved in guzzle 7) */
$this->handleUnexpectedStatus($e->getResponse()->getStatusCode(), "GuzzleFeatureRequester::getAll");
return null;
} catch (Exception $e) {
$this->_logger->error("GuzzleFeatureRequester::getAll encountered an exception retrieving all flags: " . $e->getMessage());
return null;
}
}

Expand Down
33 changes: 33 additions & 0 deletions tests/Impl/Integrations/GuzzleFeatureRequesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,37 @@ public function testSendsCorrectWrapperNameHeaders(?string $wrapper_name, ?strin
$this->assertNotContains('X-LaunchDarkly-Wrapper', $headers);
}
}

public function testTimeoutReturnsDefaultValue(): void
{
/** @var LoggerInterface **/
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();

$config = [
'logger' => $logger,
'timeout' => 1, // Set a very short timeout
'connect_timeout' => 1,
];

$client = new Client();
// Configure the mock server to delay the response by 2 seconds
$delayRule = [
'request' => [
'url' => '/sdk/flags/delayed-flag',
],
'response' => [
'fixedDelayMilliseconds' => 2000,
'status' => 200,
'body' => '{"key": "delayed-flag", "version": 1}'
]
];

$client->request('POST', 'http://localhost:8080/__admin/mappings', ['json' => $delayRule]);

$requester = new GuzzleFeatureRequester('http://localhost:8080', 'sdk-key', $config);
$result = $requester->getFeature("delayed-flag");

// The request should timeout and return null (default value) instead of throwing an exception
$this->assertNull($result);
}
}