Skip to content

Commit

Permalink
Merge pull request #224 from monsieurbiz/fix/automapper-type-error-ha…
Browse files Browse the repository at this point in the history
…ndling
  • Loading branch information
maximehuran authored Oct 21, 2024
2 parents 9122b37 + 6d0c77f commit 3423cda
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Index/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Sylius\Component\Resource\Model\TranslatableInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use TypeError;

final class Indexer implements IndexerInterface
{
Expand Down Expand Up @@ -192,7 +193,16 @@ private function indexDocumentable(OutputInterface $output, DocumentableInterfac
if (null !== $locale && $item instanceof TranslatableInterface) {
$item->setCurrentLocale($locale);
}
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());

try {
$dto = $this->autoMapper->map($item, $documentable->getTargetClass());
} catch (TypeError $e) {
$id = method_exists($item, 'getId') ? $item->getId() : 'unknown';
$output->writeln(\sprintf('Error while mapping %s (id: %s): %s', $item::class, $id, $e->getMessage()));

continue;
}

// @phpstan-ignore-next-line
$indexer->scheduleIndex($newIndex, new Document((string) $dto->getId(), $dto));
}
Expand Down

0 comments on commit 3423cda

Please sign in to comment.