|
3 | 3 | namespace Algolia\AlgoliaSearch\Console\Command;
|
4 | 4 |
|
5 | 5 | use Algolia\AlgoliaSearch\Api\Product\ReplicaManagerInterface;
|
| 6 | +use Algolia\AlgoliaSearch\Exception\ReplicaLimitExceededException; |
6 | 7 | use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
|
| 8 | +use Algolia\AlgoliaSearch\Exceptions\BadRequestException; |
7 | 9 | use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
|
8 | 10 | use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
|
9 | 11 | use Magento\Framework\App\Area;
|
@@ -91,7 +93,17 @@ function($storeId) {
|
91 | 93 |
|
92 | 94 | $this->output = $output;
|
93 | 95 | $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 | + } |
95 | 107 |
|
96 | 108 | return Cli::RETURN_SUCCESS;
|
97 | 109 | }
|
@@ -135,7 +147,13 @@ protected function syncReplicas(array $storeIds = []): void
|
135 | 147 | protected function syncReplicasForStore(int $storeId): void
|
136 | 148 | {
|
137 | 149 | $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 | + } |
139 | 157 | }
|
140 | 158 |
|
141 | 159 | /**
|
|
0 commit comments