Skip to content

Commit 209a5b3

Browse files
committed
MAGE-681 - Check error code when index doesn't exist already
1 parent 84069b4 commit 209a5b3

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

Helper/AlgoliaHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ public function generateSearchSecuredApiKey($key, $params = [])
193193

194194
public function getSettings($indexName)
195195
{
196-
return $this->getIndex($indexName)->getSettings();
196+
try {
197+
return $this->getIndex($indexName)->getSettings();
198+
}catch (\Exception $e) {
199+
if ($e->getCode() !== 404) {
200+
throw $e;
201+
}
202+
}
197203
}
198204

199205
public function mergeSettings($indexName, $settings, $mergeSettingsFrom = '')

Helper/Entity/ProductHelper.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
473473
$replicas = array_values(array_unique(array_merge($replicas, $currentSettings['replicas'])));
474474
}
475475
} catch (AlgoliaException $e) {
476-
if ($e->getMessage() !== 'Index does not exist') {
476+
if ($e->getCode() !== 404) {
477477
throw $e;
478478
}
479479
}
@@ -518,7 +518,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
518518
Copying synonyms from production index to TMP one to not erase them with the index move.
519519
');
520520
} catch (AlgoliaException $e) {
521-
$this->logger->error('Error encountered while copying synonyms: ' . $e->getMessage());
521+
$this->logger->log('Error encountered while copying synonyms: ' . $e->getMessage());
522522
}
523523

524524
try {
@@ -527,9 +527,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
527527
Copying query rules to "' . $indexNameTmp . '" to not to erase them with the index move.
528528
');
529529
} catch (AlgoliaException $e) {
530-
// Fail silently if query rules are disabled on the app
531-
// If QRs are disabled, nothing will happen and the extension will work as expected
532-
if ($e->getMessage() !== 'Query Rules are not enabled on this application') {
530+
if ($e->getCode() !== 404) {
533531
throw $e;
534532
}
535533
}
@@ -1366,9 +1364,7 @@ protected function clearFacetsQueryRules(SearchIndex $index)
13661364
$page++;
13671365
} while (($page * $hitsPerPage) < $fetchedQueryRules['nbHits']);
13681366
} catch (AlgoliaException $e) {
1369-
// Fail silently if query rules are disabled on the app
1370-
// If QRs are disabled, nothing will happen and the extension will work as expected
1371-
if ($e->getMessage() !== 'Query Rules are not enabled on this application') {
1367+
if ($e->getCode() !== 404) {
13721368
throw $e;
13731369
}
13741370
}

Helper/MerchandisingHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ public function copyQueryRules($storeId, $entityIdFrom, $entityIdTo, $entityType
160160
]);
161161
}
162162
} catch (AlgoliaException $e) {
163-
// Fail silently if query rules are disabled on the app
164-
// If QRs are disabled, nothing will happen and the extension will work as expected
165-
if ($e->getMessage() !== 'Query Rules are not enabled on this application') {
163+
if ($e->getCode() !== 404) {
166164
throw $e;
167165
}
168166
}

Model/Observer/SaveSettings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SaveSettings implements ObserverInterface
2525
protected $algoliaHelper;
2626

2727
/**
28-
* @var AlgoliaHelper
28+
* @var Data
2929
*/
3030
protected $helper;
3131

@@ -79,7 +79,7 @@ public function execute(Observer $observer)
7979
}
8080
}
8181
} catch (\Exception $e) {
82-
if ($e->getMessage() !== 'Index does not exist') {
82+
if ($e->getCode() !== 404) {
8383
throw $e;
8484
}
8585
}

0 commit comments

Comments
 (0)