Skip to content

Commit eba2d8e

Browse files
committed
make ExceptionEvent handle all throwables
1 parent da437e2 commit eba2d8e

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/Symfony/Component/HttpKernel/Event/ExceptionEvent.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,33 @@
2929
*/
3030
final class ExceptionEvent extends RequestEvent
3131
{
32-
/**
33-
* The exception object.
34-
*
35-
* @var \Exception
36-
*/
37-
private $exception;
32+
private $throwable;
3833

3934
/**
4035
* @var bool
4136
*/
4237
private $allowCustomResponseCode = false;
4338

44-
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Exception $e)
39+
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Throwable $e)
4540
{
4641
parent::__construct($kernel, $request, $requestType);
4742

48-
$this->setException($e);
43+
$this->setThrowable($e);
4944
}
5045

51-
public function getException(): \Exception
46+
public function getThrowable(): \Throwable
5247
{
53-
return $this->exception;
48+
return $this->throwable;
5449
}
5550

5651
/**
5752
* Replaces the thrown exception.
5853
*
5954
* This exception will be thrown if no response is set in the event.
6055
*/
61-
public function setException(\Exception $exception): void
56+
public function setThrowable(\Throwable $exception): void
6257
{
63-
$this->exception = $exception;
58+
$this->throwable = $exception;
6459
}
6560

6661
/**

src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function __construct($controller, LoggerInterface $logger = null, bool $d
4242

4343
public function logKernelException(ExceptionEvent $event)
4444
{
45-
$e = FlattenException::createFromThrowable($event->getException());
45+
$e = FlattenException::createFromThrowable($event->getThrowable());
4646

47-
$this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
47+
$this->logException($event->getThrowable(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
4848
}
4949

5050
public function onKernelException(ExceptionEvent $event, string $eventName = null, EventDispatcherInterface $eventDispatcher = null)
@@ -53,7 +53,7 @@ public function onKernelException(ExceptionEvent $event, string $eventName = nul
5353
return;
5454
}
5555

56-
$exception = $event->getException();
56+
$exception = $event->getThrowable();
5757
$request = $this->duplicateRequest($exception, $event->getRequest());
5858

5959
try {
@@ -98,7 +98,7 @@ public static function getSubscribedEvents(): array
9898
];
9999
}
100100

101-
protected function logException(\Exception $exception, string $message)
101+
protected function logException(\Throwable $exception, string $message)
102102
{
103103
if (null !== $this->logger) {
104104
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
@@ -112,7 +112,7 @@ protected function logException(\Exception $exception, string $message)
112112
/**
113113
* Clones the request for the exception.
114114
*/
115-
protected function duplicateRequest(\Exception $exception, Request $request): Request
115+
protected function duplicateRequest(\Throwable $exception, Request $request): Request
116116
{
117117
$attributes = [
118118
'_controller' => $this->controller,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy