Skip to content

Commit a38c014

Browse files
committed
MAGE-938 Add error handling to replica sync CLI
1 parent 0b06f75 commit a38c014

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Console/Command/ReplicaCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Algolia\AlgoliaSearch\Console\Command;
44

55
use Algolia\AlgoliaSearch\Api\Product\ReplicaManagerInterface;
6+
use Algolia\AlgoliaSearch\Exception\ReplicaLimitExceededException;
67
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
8+
use Algolia\AlgoliaSearch\Exceptions\BadRequestException;
79
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
810
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
911
use Magento\Framework\App\Area;
@@ -91,7 +93,17 @@ function($storeId) {
9193

9294
$this->output = $output;
9395
$this->state->setAreaCode(Area::AREA_ADMINHTML);
94-
$this->syncReplicas($storeIds);
96+
try {
97+
$this->syncReplicas($storeIds);
98+
} catch (BadRequestException $e) {
99+
$this->output->writeln('<comment>You appear to have a corrupted replica configuration in Algolia for your Magento instance.</comment>');
100+
$this->output->writeln('<comment>Run the "algolia:replicas:rebuild" command to correct this.</comment>');
101+
return CLI::RETURN_FAILURE;
102+
} catch (ReplicaLimitExceededException $e) {
103+
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
104+
$this->output->writeln('<comment>Reduce the number of sorting attributes that have enabled virtual replicas and try again.</comment>');
105+
return CLI::RETURN_FAILURE;
106+
}
95107

96108
return Cli::RETURN_SUCCESS;
97109
}
@@ -135,7 +147,13 @@ protected function syncReplicas(array $storeIds = []): void
135147
protected function syncReplicasForStore(int $storeId): void
136148
{
137149
$this->output->writeln('<info>Syncing ' . $this->getStoreName($storeId) . '...</info>');
138-
$this->replicaManager->syncReplicasToAlgolia($storeId, $this->productHelper->getIndexSettings($storeId));
150+
try {
151+
$this->replicaManager->syncReplicasToAlgolia($storeId, $this->productHelper->getIndexSettings($storeId));
152+
}
153+
catch (BadRequestException $e) {
154+
$this->output->writeln('<error>Failed syncing replicas for store "' . $this->getStoreName($storeId) . '": ' . $e->getMessage() . '</error>');
155+
throw $e;
156+
}
139157
}
140158

141159
/**

0 commit comments

Comments
 (0)