forked from getsentry/sentry-symfony
/
ErrorListener.php
41 lines (34 loc) · 1.11 KB
/
ErrorListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Sentry\SentryBundle\EventListener;
use Sentry\State\HubInterface;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
final class ErrorListener
{
/** @var HubInterface */
private $hub;
/**
* ErrorListener constructor.
* @param HubInterface $hub
*/
public function __construct(HubInterface $hub)
{
$this->hub = $hub; // not used, needed to trigger instantiation
}
public function onKernelException(GetResponseForExceptionEvent $event): void
{
\Sentry\captureException($event->getException());
}
public function onConsoleError(ConsoleErrorEvent $event): void
{
\Sentry\captureException($event->getError());
}
/**
* BC layer for Symfony < 3.3; see https://symfony.com/blog/new-in-symfony-3-3-better-handling-of-command-exceptions
*/
public function onConsoleException(ConsoleExceptionEvent $event): void
{
\Sentry\captureException($event->getException());
}
}