Skip to content

Commit

Permalink
Catch Infimum API exceptions
Browse files Browse the repository at this point in the history
Prevent the website from displaying nothing randomly at night when
LIS decides to restart some of their networking equipment.
  • Loading branch information
tomudding committed Oct 27, 2023
1 parent 2886696 commit 3cf3c2d
Showing 1 changed file with 14 additions and 9 deletions.
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

0 comments on commit 3cf3c2d

Please sign in to comment.