|
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,13 +47,25 @@ 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 | 52 | if ($throwable instanceof $class && $config['log_level']) {
|
51 | 53 | $logLevel = $config['log_level'];
|
52 | 54 | break;
|
53 | 55 | }
|
54 | 56 | }
|
55 | 57 |
|
| 58 | + foreach ($this->exceptionsMapping as $class => $config) { |
| 59 | + if ($throwable instanceof $class && $config['status_code']) { |
| 60 | + if (!$throwable instanceof HttpExceptionInterface || $throwable->getStatusCode() !== $config['status_code']) { |
| 61 | + $headers = $throwable instanceof HttpExceptionInterface ? $throwable->getHeaders() : []; |
| 62 | + $throwable = new HttpException($config['status_code'], $throwable->getMessage(), $throwable, $headers); |
| 63 | + $event->setThrowable($throwable); |
| 64 | + } |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | + |
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']); |
94 |
| - break; |
95 |
| - } |
96 |
| - } |
97 |
| - |
98 | 104 | $event->setResponse($response);
|
99 | 105 |
|
100 | 106 | if ($this->debug) {
|
|
0 commit comments