Skip to content

Commit 30740ac

Browse files
committed
MAGE-839 Add error handling for settings retrieval
1 parent 74411c0 commit 30740ac

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

Model/Product/ReplicaManager.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,25 @@ protected function hasReplicaConfigurationChanged(string $primaryIndexName, int
7777
}
7878
}
7979

80-
protected function getReplicaConfigurationFromAlgolia($primaryIndexName, bool $refreshCache = false)
80+
/**
81+
* @param $primaryIndexName
82+
* @param bool $refreshCache
83+
* @return array<string, mixed>
84+
* @throws LocalizedException
85+
*/
86+
protected function getReplicaConfigurationFromAlgolia($primaryIndexName, bool $refreshCache = false): array
8187
{
8288
if ($refreshCache || !isset($this->_algoliaReplicaConfig[$primaryIndexName])) {
83-
$currentSettings = $this->algoliaHelper->getSettings($primaryIndexName);
84-
$this->_algoliaReplicaConfig[$primaryIndexName] = array_key_exists('replicas', $currentSettings)
85-
? $currentSettings['replicas']
86-
: [];
89+
try {
90+
$currentSettings = $this->algoliaHelper->getSettings($primaryIndexName);
91+
$this->_algoliaReplicaConfig[$primaryIndexName] = array_key_exists('replicas', $currentSettings)
92+
? $currentSettings['replicas']
93+
: [];
94+
} catch (\Exception $e) {
95+
$msg = "Unable to retrieve replica settings for $primaryIndexName: " . $e->getMessage();
96+
$this->logger->error($msg);
97+
throw new LocalizedException(__($msg));
98+
}
8799
}
88100
return $this->_algoliaReplicaConfig[$primaryIndexName];
89101
}
@@ -103,6 +115,7 @@ protected function clearAlgoliaReplicaSettingCache($primaryIndexName = null): vo
103115
*
104116
* @param string $primaryIndexName
105117
* @return string[]
118+
* @throws LocalizedException
106119
*/
107120
protected function getMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName): array
108121
{
@@ -130,6 +143,7 @@ function ($algoliaReplicaSetting) use ($baseIndexName) {
130143
/**
131144
* @param string $primaryIndexName
132145
* @return array
146+
* @throws LocalizedException
133147
*/
134148
protected function getNonMagentoReplicaConfigurationFromAlgolia(string $primaryIndexName): array
135149
{

0 commit comments

Comments
 (0)