for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class ExceptionListener implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public function onKernelException(GetResponseForExceptionEvent $event)
if (\getenv('APP_ENV') === 'dev') {
// for dev env we need to show all exception data
return;
}
$exception = $event->getException();
$response = new JsonResponse([
'error' => $exception->getMessage(),
]);
$event->setResponse($response);
public static function getSubscribedEvents()
return array(
KernelEvents::EXCEPTION => array('onKernelException', -100),
);