diff --git a/composer.json b/composer.json index 3abcadb2c..c02b5cf46 100644 --- a/composer.json +++ b/composer.json @@ -120,7 +120,8 @@ "autoload": { "psr-4": { "App\\": "src/" - } + }, + "classmap": ["src/"] }, "autoload-dev": { "psr-4": { diff --git a/src/EventListener/RequestStatsListener.php b/src/EventListener/RequestStatsListener.php index b1485bfe9..d67b80dde 100644 --- a/src/EventListener/RequestStatsListener.php +++ b/src/EventListener/RequestStatsListener.php @@ -17,8 +17,10 @@ use Monolog\Logger; use Monolog\LogRecord; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; class RequestStatsListener { @@ -69,4 +71,12 @@ public function onResponse(ResponseEvent $e): void }; $this->statsd->increment('app.status.'.$statsdCode, 1, 1, ['route' => $e->getRequest()->attributes->get('_route')]); } + + #[AsEventListener()] + public function onException(ExceptionEvent $e): void + { + if ($e->getThrowable() instanceof BadRequestHttpException && $e->getThrowable()->getCode() !== 404) { + $this->logger->error('Bad request', ['exception' => $e->getThrowable()]); + } + } }