|
19 | 19 | use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
|
20 | 20 | use Symfony\Component\HttpKernel\Event\ExceptionEvent;
|
21 | 21 | use Symfony\Component\HttpKernel\Event\ResponseEvent;
|
| 22 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
22 | 23 | use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
23 | 24 | use Symfony\Component\HttpKernel\HttpKernelInterface;
|
24 | 25 | use Symfony\Component\HttpKernel\KernelEvents;
|
@@ -46,9 +47,19 @@ public function logKernelException(ExceptionEvent $event)
|
46 | 47 | {
|
47 | 48 | $throwable = $event->getThrowable();
|
48 | 49 | $logLevel = null;
|
| 50 | + |
49 | 51 | foreach ($this->exceptionsMapping as $class => $config) {
|
50 |
| - if ($throwable instanceof $class && $config['log_level']) { |
| 52 | + if (!$throwable instanceof $class) { |
| 53 | + continue; |
| 54 | + } |
| 55 | + if ($config['log_level'] && null === $logLevel) { |
51 | 56 | $logLevel = $config['log_level'];
|
| 57 | + } |
| 58 | + if ($config['status_code'] && $event->getThrowable() === $throwable) { |
| 59 | + $throwable = new HttpException($config['status_code'], $throwable->getMessage(), $throwable); |
| 60 | + $event->setThrowable($throwable); |
| 61 | + } |
| 62 | + if (null !== $logLevel && $event->getThrowable() !== $throwable) { |
52 | 63 | break;
|
53 | 64 | }
|
54 | 65 | }
|
@@ -88,13 +99,6 @@ public function onKernelException(ExceptionEvent $event)
|
88 | 99 | throw $e;
|
89 | 100 | }
|
90 | 101 |
|
91 |
| - foreach ($this->exceptionsMapping as $exception => $config) { |
92 |
| - if ($throwable instanceof $exception && $config['status_code']) { |
93 |
| - $response->setStatusCode($config['status_code']); |
94 |
| - break; |
95 |
| - } |
96 |
| - } |
97 |
| - |
98 | 102 | $event->setResponse($response);
|
99 | 103 |
|
100 | 104 | if ($this->debug) {
|
|
0 commit comments