5

I try to handle an exception from a Symfony console command in a Symfony 4 project.

This is my event listener in services.yaml:

kernel.event_listener:
        class: App\Application\EventListener\ExceptionListener
        arguments:
            - '@logger'
            - '@jms_serializer'
            - '@translator.default'
        tags:
            - { name: kernel.event_listener, event: kernel.exception, method: onConsoleException }

What is the tag for this treatment?

1 Answer 1

10

The correct configuration is this:

kernel.event_listener:
        class: App\Application\EventListener\ExceptionListener
        arguments:
            - '@logger'
            - '@jms_serializer'
            - '@translator.default'
        tags:
            - { name: kernel.event_listener, event: console.error }

And your exception listener:

namespace App\EventListener;

use Symfony\Component\Console\Event\ConsoleErrorEvent;

class ExceptionListener
{
    public function onConsoleError(ConsoleErrorEvent $event) {
        // your code here
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thx for you help @iiirxs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.