Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Infimum API exceptions #1745

Merged
merged 1 commit into from
Oct 27, 2023
Merged
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
23 changes: 14 additions & 9 deletions module/Application/src/Service/Infimum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
use Laminas\Http\Client;
use Laminas\Http\Client\Adapter\Curl;
use Laminas\Http\Client\Adapter\Exception\RuntimeException;
use Laminas\Http\Request;
use Laminas\Json\Json;
use Laminas\Mvc\I18n\Translator;
Expand Down Expand Up @@ -48,19 +49,23 @@ public function getInfimum(): string
$client->setAdapter(Curl::class)
->setEncType('application/json');

$response = $client->send($request);
try {
$response = $client->send($request);

// Check if the request was successful.
if (200 === $response->getStatusCode()) {
$responseContent = Json::decode($response->getBody(), Json::TYPE_ARRAY);
// Check if the request was successful.
if (200 === $response->getStatusCode()) {
$responseContent = Json::decode($response->getBody(), Json::TYPE_ARRAY);

// Check if an Infimum is returned.
if (array_key_exists('content', $responseContent)) {
// Cache the infimum to reduce the number of requests that need to be executed.
$this->infimumCache->setItem('infimum', $responseContent['content']);
// Check if an Infimum is returned.
if (array_key_exists('content', $responseContent)) {
// Cache the infimum to reduce the number of requests that need to be executed.
$this->infimumCache->setItem('infimum', $responseContent['content']);

return $responseContent['content'];
return $responseContent['content'];
}
}
} catch (RuntimeException) {
// cURL threw an error and the page could not be loaded.
}

return $this->translator->translate('Unable to retrieve infimum.');
Expand Down
Loading