Skip to content

[HttpKernel] ErrorListener doesnt convert throwable to legacy FlattenException for controller argument #34661

@andrew-demb

Description

@andrew-demb

Symfony version(s) affected: 4.4.0

Description

ErrorListener doesnt convert throwable to legacy FlattenException for controller argument and it leads to exception:

Argument 1 passed to ExceptionController::__invoke() must be an instance of Symfony\Component\Debug\Exception\FlattenException, instance of TypeError given, called in /.../vendor/symfony/http-kernel/HttpKernel.php on line 146

How to reproduce

Declare controller with Symfony\Component\Debug\Exception\FlattenException argument,
use Symfony\Component\HttpKernel\EventListener\ErrorListener with configured reference to controller.

Possible Solution

Check Symfony\Component\Debug\Exception\FlattenException here

if ($r && (!$r->hasType() || FlattenException::class === $r->getType()->getName())) {

Additional context

DI config:

services:
  exception_error.listener:
  class: Symfony\Component\HttpKernel\EventListener\ExceptionListener
  tags:
    - { name: kernel.event_listener, event: kernel.exception, method: onKernelException, priority: -1 }
  arguments:
    - 'ExceptionController'
    - '@?logger'

Controller example:

use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\JsonResponse;

class ExceptionController
{
    public function __invoke(FlattenException $exception): JsonResponse
    {
        return new JsonResponse(['message' => $exception->getMessage(), 'failed' => true]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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