-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
# ...
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
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! 👍 |
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! |