Skip to content

Commit

Permalink
Use Throwable instead of Exception in the exception and error listene…
Browse files Browse the repository at this point in the history
…rs (see #1050)

Description
-----------

The PR fixes problems like this:

`
Argument 1 passed to Contao\CoreBundle\EventListener\ExceptionConverterListener::getTargetClass() must be an instance of Exception, instance of Symfony\Component\ErrorHandler\Error\UndefinedFunctionError given, called in vendor/contao/contao/core-bundle/src/EventListener/ExceptionConverterListener.php on line 59
`

Commits
-------

ffe0c98 Use Throwable instead of Exception in the exception and error listeners
  • Loading branch information
leofeyer committed Dec 4, 2019
1 parent 23630c1 commit b2976b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core-bundle/src/EventListener/ExceptionConverterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function onKernelException(ExceptionEvent $event): void
}
}

private function getTargetClass(\Exception $exception): ?string
private function getTargetClass(\Throwable $exception): ?string
{
foreach (self::MAPPER as $source => $target) {
if ($exception instanceof $source) {
Expand All @@ -78,7 +78,7 @@ private function getTargetClass(\Exception $exception): ?string
return null;
}

private function convertToHttpException(\Exception $exception, string $target): ?HttpException
private function convertToHttpException(\Throwable $exception, string $target): ?HttpException
{
switch ($target) {
case 'AccessDeniedHttpException':
Expand Down
6 changes: 3 additions & 3 deletions core-bundle/src/EventListener/PrettyErrorScreenListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private function getTemplateParameters(string $view, int $statusCode, ExceptionE
];
}

private function logException(\Exception $exception): void
private function logException(\Throwable $exception): void
{
if (Kernel::VERSION_ID >= 40100 || null === $this->logger || !$this->isLoggable($exception)) {
return;
Expand All @@ -240,7 +240,7 @@ private function logException(\Exception $exception): void
$this->logger->critical('An exception occurred.', ['exception' => $exception]);
}

private function isLoggable(\Exception $exception): bool
private function isLoggable(\Throwable $exception): bool
{
do {
if ($exception instanceof InvalidRequestTokenException) {
Expand All @@ -251,7 +251,7 @@ private function isLoggable(\Exception $exception): bool
return true;
}

private function getStatusCodeForException(\Exception $exception): int
private function getStatusCodeForException(\Throwable $exception): int
{
if ($exception instanceof HttpException) {
return (int) $exception->getStatusCode();
Expand Down

0 comments on commit b2976b7

Please sign in to comment.