|
19 | 19 | use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
|
20 | 20 | use Symfony\Component\HttpKernel\Eve
8000
nt\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,13 +47,25 @@ public function logKernelException(ExceptionEvent $event)
|
46 | 47 | {
|
47 | 48 | $throwable = $event->getThrowable();
|
48 | 49 | $logLevel = null;
|
49 |
| - foreach ($this->exceptionsMapping as $class => $config) { |
50 |
| - if ($throwable instanceof $class && $config['log_level']) { |
51 |
| - $logLevel = $config['log_level']; |
52 |
| - break; |
| 50 | + |
| 51 | + if (!$throwable instanceof HttpExceptionInterface) { |
| 52 | + foreach ($this->exceptionsMapping as $class => $config) { |
| 53 | + if (!$throwable instanceof $class) { |
| 54 | + continue; |
| 55 | + } |
| 56 | + if ($config['log_level'] && null === $logLevel) { |
| 57 | + $logLevel = $config['log_level']; |
| 58 | + } |
| 59 | + if ($config['status_code'] && $event->getThrowable() === $throwable) { |
| 60 | + $throwable = new HttpException($config['status_code'], $throwable->getMessage(), $throwable); |
| 61 | + } |
| 62 | + if (null !== $logLevel && $event->getThrowable() !== $throwable) { |
| 63 | + break; |
| 64 | + } |
53 | 65 | }
|
54 | 66 | }
|
55 | 67 |
|
| 68 | + $event->setThrowable($throwable); |
56 | 69 | $e = FlattenException::createFromThrowable($throwable);
|
57 | 70 |
|
58 | 71 | $this->logException($throwable, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()), $logLevel);
|
@@ -88,13 +101,6 @@ public function onKernelException(ExceptionEvent $event)
|
88 | 101 | throw $e;
|
89 | 102 | }
|
90 | 103 |
|
91 |
| - foreach ($this->exceptionsMapping as $exception => $config) { |
92 |
| - if ($throwable instanceof $exception && $config['status_code']) { |
93 |
| - $response->setStatusCode($config['status_code']); |
8000
94 |
| - break; |
95 |
| - } |
96 |
| - } |
97 |
| - |
98 | 104 | $event->setResponse($response);
|
99 | 105 |
|
100 | 106 | if ($this->debug) {
|
|
0 commit comments