File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ /*
4+ * This file is part of Packagist.
5+ *
6+ * (c) Jordi Boggiano <j.boggiano@seld.be>
7+ * Nils Adermann <naderman@naderman.de>
8+ *
9+ * For the full copyright and license information, please view the LICENSE
10+ * file that was distributed with this source code.
11+ */
12+
13+ namespace App \EventListener ;
14+
15+ use Symfony \Component \EventDispatcher \Attribute \AsEventListener ;
16+ use Symfony \Component \HttpKernel \Event \ExceptionEvent ;
17+ use Symfony \Component \HttpFoundation \Exception \BadRequestException ;
18+ use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
19+ use Twig \Error \RuntimeError ;
20+
21+ /**
22+ * Converts BadRequestException to BadRequestHttpException
23+ */
24+ class BadRequestExceptionListener
25+ {
26+ #[AsEventListener(priority: 1000 )]
27+ public function onKernelException (ExceptionEvent $ event ): void
28+ {
29+ $ exception = $ event ->getThrowable ();
30+
31+ if ($ exception instanceof RuntimeError) {
32+ $ exception = $ exception ->getPrevious ();
33+ }
34+ if ($ exception instanceof BadRequestException) {
35+ $ event ->setThrowable (new BadRequestHttpException ($ exception ->getMessage (), $ exception ));
36+ }
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments