Skip to content

Example of handling exceptions with listeners #5503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mdburgos
Copy link

@mdburgos mdburgos commented Jul 8, 2015

Q A
Doc fix? yes
New docs? no
Applies to all
Fixed tickets #4181


# app/config/services.yml
services:
kernel.listener.your_exception_listener_name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name isn't used anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it will be called automatically when an exception occurs since we’re listening to the kernel.exception event

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For modern cookbook articles, we try to follow the official best practices of using short services names prefixed with app. Something like the following will be enough:

# app/config/services.yml
services:
    app.exception_listener:
        # ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Javier, will change it

use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;

class AcmeExceptionListener
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have a dedicated AppBundle, we no longer need to use "Acme". Let's just name this ExceptionListener.

@xabbuh
Copy link
Member

xabbuh commented Mar 31, 2016

Hi @mdburgos, I am fully sorry that we did not review your pull request yet. I left you some minor comments, but overall this is some really great work! 👍

@weaverryan
Copy link
Member

I'm closing this. @mdburgos thanks for making this PR. This was our fault honestly - we allowed this PR to become too old, and it's now against a very old branch. Also, I'd like to take a different approach, described here: #4181 (comment)

I hope you'l contribute again to the docs!

@weaverryan weaverryan closed this Jul 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants