symfony 4 - bugsnag - Ignore specific exception type

zoz*_*ozo 5 php events symfony bugsnag symfony4

I use bugsnag to log errors for our app. The app is built over symfony 4 and I have a custom listener that catches exceptions and treats some of them. What I need is to tell bugsnag to ignore the exceptions that I manually handle (there is no need for them to be logged since they are already treated).

My custom listener has higher priority than bugsnag listener (so is ran first). The problem is that stopping event propagation breaks other stuff (for example security listener is not run any more since it has lower priority than bugsnag by default).

Below is my listener code (well... relevant part of it):

class ExceptionListener
{

protected $router;
private $mailerService;
private $tokenStorage;
private $request;
private $em;
/**
 * @var UtilsService
 */
private $utilsService;

public function __construct(Router $router, MailerService $mailerService, TokenStorageInterface $tokenStorage, RequestStack $request, EntityManagerInterface $em, UtilsService $utilsService)
{
    $this->router = $router;
    $this->mailerService = $mailerService;
    $this->tokenStorage = $tokenStorage;
    $this->request = $request;
    $this->em = $em;
    $this->utilsService = $utilsService;
}

public function onKernelException(ExceptionEvent $event)
{
    $exception = $event->getException();
    $message = $exception->getMessage();

    switch (true) {
        case $exception instanceof NotFoundHttpException:
             // Redirect somewhere
        break;
        case $exception instanceof CustomException:
             // Do some stuff
             $event->stopPropagation(); // This does what I need (stops propagation to bugsnag listener) but breaks other things so is not a solution (since it stops propagation to everything).
        break;
    }

    return false;
}
}
Run Code Online (Sandbox Code Playgroud)

What I need is simple... in case the exception thrown is an instance of CustomException I want it NOT to be sent to bugsnag.

The 2 possible solutions that I see are (others are welcomed ofc):

小智 3

您可以实现回调并检查报告对象,如下所述: https ://docs.bugsnag.com/platforms/php/symfony/configuration-options/#callbacks

false只需从回调中返回即可防止向 Bugsnag 报告。