Skip to content

Commit e075f15

Browse files
committed
Add the SentryExceptionListenerInterface
The SentryExceptionListenerInterface serves as a contract enforcing the shape of the exception listener. The shape is important because, for Sentry exception listeners, it is necessary to capture exceptions coming from both web requests (GetResponseForExceptionEvents) and the console (ConsoleExceptionEvents).
1 parent f7c8d8d commit e075f15

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ sentry:
146146
// src/AppBundle/EventSubscriber/MySentryEventListener.php
147147
namespace AppBundle\EventSubscriber;
148148
149+
use Sentry\SentryBundle\EventListener\SentryExceptionListenerInterface;
149150
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
150151
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
151152
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
152153
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
153154
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
154155
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
155156
156-
class MySentryExceptionListener
157+
class MySentryExceptionListener implements SentryExceptionListenerInterface
157158
{
158159
// ...
159160

src/Sentry/SentryBundle/EventListener/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Class ExceptionListener
2121
* @package Sentry\SentryBundle\EventListener
2222
*/
23-
class ExceptionListener
23+
class ExceptionListener implements SentryExceptionListenerInterface
2424
{
2525
/** @var TokenStorageInterface */
2626
private $tokenStorage;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Sentry\SentryBundle\EventListener;
4+
5+
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
6+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
7+
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
8+
9+
interface SentryExceptionListenerInterface
10+
{
11+
12+
/**
13+
* Used to capture information from the request before any possible error
14+
* event is encountered by listening on core.request.
15+
*
16+
* Most commonly used for assigning the username to the security context
17+
* used by Sentry for each request.
18+
*
19+
* @param GetResponseEvent $event
20+
*/
21+
function onKernelRequest(GetResponseEvent $event);
22+
23+
/**
24+
* When an exception occurs as part of a web request, this method will be
25+
* triggered for capturing the error.
26+
*
27+
* @param GetResponseForExceptionEvent $event
28+
*/
29+
function onKernelException(GetResponseForExceptionEvent $event);
30+
31+
/**
32+
* When an exception occurs on the command line, this method will be
33+
* triggered for capturing the error.
34+
*
35+
* @param ConsoleExceptionEvent $event
36+
*/
37+
function onConsoleException(ConsoleExceptionEvent $event);
38+
39+
}

0 commit comments

Comments
 (0)