DelayedMessageHandlingException.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Exception;
  11. /**
  12. * When handling queued messages from {@link DispatchAfterCurrentBusMiddleware},
  13. * some handlers caused an exception. This exception contains all those handler exceptions.
  14. *
  15. * @author Tobias Nyholm <tobias.nyholm@gmail.com>
  16. */
  17. class DelayedMessageHandlingException extends RuntimeException
  18. {
  19. private $exceptions;
  20. public function __construct(array $exceptions)
  21. {
  22. $exceptionMessages = implode(", \n", array_map(
  23. function (\Throwable $e) {
  24. return \get_class($e).': '.$e->getMessage();
  25. },
  26. $exceptions
  27. ));
  28. if (1 === \count($exceptions)) {
  29. $message = sprintf("A delayed message handler threw an exception: \n\n%s", $exceptionMessages);
  30. } else {
  31. $message = sprintf("Some delayed message handlers threw an exception: \n\n%s", $exceptionMessages);
  32. }
  33. $this->exceptions = $exceptions;
  34. parent::__construct($message, 0, $exceptions[0]);
  35. }
  36. public function getExceptions(): array
  37. {
  38. return $this->exceptions;
  39. }
  40. }