vendor/sentry/sentry-symfony/src/EventListener/ErrorListener.php line 38

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sentry\SentryBundle\EventListener;
  4. use Sentry\Event;
  5. use Sentry\EventHint;
  6. use Sentry\ExceptionMechanism;
  7. use Sentry\State\HubInterface;
  8. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  9. /**
  10. * This listener listens for error events and logs them to Sentry.
  11. */
  12. final class ErrorListener
  13. {
  14. /**
  15. * @var HubInterface The current hub
  16. */
  17. private $hub;
  18. /**
  19. * Constructor.
  20. *
  21. * @param HubInterface $hub The current hub
  22. */
  23. public function __construct(HubInterface $hub)
  24. {
  25. $this->hub = $hub;
  26. }
  27. /**
  28. * Handles an exception that happened while running the application.
  29. *
  30. * @param ExceptionEvent $event The event
  31. */
  32. public function handleExceptionEvent(ExceptionEvent $event): void
  33. {
  34. $hint = EventHint::fromArray([
  35. 'exception' => $event->getThrowable(),
  36. 'mechanism' => new ExceptionMechanism(ExceptionMechanism::TYPE_GENERIC, false),
  37. ]);
  38. $this->hub->captureEvent(Event::createEvent(), $hint);
  39. }
  40. }