minor #34319 [Security] make ExceptionEvent handle all throwables (xabbuh)
This PR was merged into the 5.0-dev branch.
Discussion
----------
[Security] make ExceptionEvent handle all throwables
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
fixes `master` after merging #34309 up
Commits
-------
eba2d8efc9
make ExceptionEvent handle all throwables
This commit is contained in:
commit
b1b45a568d
@ -29,28 +29,23 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
*/
|
||||
final class ExceptionEvent extends RequestEvent
|
||||
{
|
||||
/**
|
||||
* The exception object.
|
||||
*
|
||||
* @var \Exception
|
||||
*/
|
||||
private $exception;
|
||||
private $throwable;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $allowCustomResponseCode = false;
|
||||
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Exception $e)
|
||||
public function __construct(HttpKernelInterface $kernel, Request $request, int $requestType, \Throwable $e)
|
||||
{
|
||||
parent::__construct($kernel, $request, $requestType);
|
||||
|
||||
$this->setException($e);
|
||||
$this->setThrowable($e);
|
||||
}
|
||||
|
||||
public function getException(): \Exception
|
||||
public function getThrowable(): \Throwable
|
||||
{
|
||||
return $this->exception;
|
||||
return $this->throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,9 +53,9 @@ final class ExceptionEvent extends RequestEvent
|
||||
*
|
||||
* This exception will be thrown if no response is set in the event.
|
||||
*/
|
||||
public function setException(\Exception $exception): void
|
||||
public function setThrowable(\Throwable $exception): void
|
||||
{
|
||||
$this->exception = $exception;
|
||||
$this->throwable = $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,9 +42,9 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
|
||||
public function logKernelException(ExceptionEvent $event)
|
||||
{
|
||||
$e = FlattenException::createFromThrowable($event->getException());
|
||||
$e = FlattenException::createFromThrowable($event->getThrowable());
|
||||
|
||||
$this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
|
||||
$this->logException($event->getThrowable(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
|
||||
}
|
||||
|
||||
public function onKernelException(ExceptionEvent $event, string $eventName = null, EventDispatcherInterface $eventDispatcher = null)
|
||||
@ -53,7 +53,7 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
$exception = $event->getException();
|
||||
$exception = $event->getThrowable();
|
||||
$request = $this->duplicateRequest($exception, $event->getRequest());
|
||||
|
||||
try {
|
||||
@ -98,7 +98,7 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
];
|
||||
}
|
||||
|
||||
protected function logException(\Exception $exception, string $message)
|
||||
protected function logException(\Throwable $exception, string $message)
|
||||
{
|
||||
if (null !== $this->logger) {
|
||||
if (!$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500) {
|
||||
@ -112,7 +112,7 @@ class ExceptionListener implements EventSubscriberInterface
|
||||
/**
|
||||
* Clones the request for the exception.
|
||||
*/
|
||||
protected function duplicateRequest(\Exception $exception, Request $request): Request
|
||||
protected function duplicateRequest(\Throwable $exception, Request $request): Request
|
||||
{
|
||||
$attributes = [
|
||||
'_controller' => $this->controller,
|
||||
|
Reference in New Issue
Block a user