vendor/symfony/messenger/EventListener/AddErrorDetailsStampListener.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Messenger\EventListener;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
  13. use Symfony\Component\Messenger\Stamp\ErrorDetailsStamp;
  14. final class AddErrorDetailsStampListener implements EventSubscriberInterface
  15. {
  16. public function onMessageFailed(WorkerMessageFailedEvent $event): void
  17. {
  18. $stamp = ErrorDetailsStamp::create($event->getThrowable());
  19. $previousStamp = $event->getEnvelope()->last(ErrorDetailsStamp::class);
  20. // Do not append duplicate information
  21. if (null === $previousStamp || !$previousStamp->equals($stamp)) {
  22. $event->addStamps($stamp);
  23. }
  24. }
  25. public static function getSubscribedEvents(): array
  26. {
  27. return [
  28. // must have higher priority than SendFailedMessageForRetryListener
  29. WorkerMessageFailedEvent::class => ['onMessageFailed', 200],
  30. ];
  31. }
  32. }