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;
}
}
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):
tell bugsnag to ignore that exception somehow: In bugsnag documentation I find how to do this for Laravel (https://docs.bugsnag.com/platforms/php/laravel/configuration-options/ - using dontReport) and Ruby (https://docs.bugsnag.com/platforms/ruby/other/configuration-options/#ignore_classes), but not for Symfony. Any idea how to do this?
stop propagation of the event only for the bugsnag listener: I found no documentation regarding this whatsoever. Any idea how to do this?
You can implement a callback and inspect the report object as described here: https://docs.bugsnag.com/platforms/php/symfony/configuration-options/#callbacks
Simply return false
from the callback to prevent reporting to Bugsnag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With