Skip to content

Commit 26c6e79

Browse files
authored
Merge pull request #1384 from algolia/feature/MAGE-681-NS-POV
MAGE-681 - Check error code when index doesn't exist already
2 parents 8ec3f5b + e9fb68b commit 26c6e79

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
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
}
@@ -1462,9 +1460,7 @@ protected function clearFacetsQueryRules(SearchIndex $index)
14621460
$page++;
14631461
} while (($page * $hitsPerPage) < $fetchedQueryRules['nbHits']);
14641462
} catch (AlgoliaException $e) {
1465-
// Fail silently if query rules are disabled on the app
1466-
// If QRs are disabled, nothing will happen and the extension will work as expected
1467-
if ($e->getMessage() !== 'Query Rules are not enabled on this application') {
1463+
if ($e->getCode() !== 404) {
14681464
throw $e;
14691465
}
14701466
}

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
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Algolia Search for Magento 2
22
============================
33

4-
![Latest version](https://img.shields.io/badge/latest-3.10.4-green)
4+
![Latest version](https://img.shields.io/badge/latest-3.10.5-green)
55
![Magento 2](https://img.shields.io/badge/Magento-2.4.x-orange)
66

77
![PHP](https://img.shields.io/badge/PHP-8.2%2C8.1%2C7.4-blue)

view/adminhtml/layout/algolia_algoliasearch_landingpage_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<argument name="view_model" xsi:type="object">Algolia\AlgoliaSearch\ViewModel\Adminhtml\Common</argument>
2020
</arguments>
2121
</block>
22-
</referenceBlock>
22+
</referenceContainer>
2323
</body>
2424
</page>

0 commit comments

Comments
 (0)