-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Document the handling of exceptions with listeners #4181
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
Comments
I think this is a nice idea and should be added to this page: http://symfony.com/doc/current/cookbook/controller/error_pages.html. Notice that we show 2 options at the top currently, and this should be 3. We can then add a short section at the bottom showing a quick example of throwing your own exception class and then catching it in a listener to render a custom error page. Also, the 2 (soon to be 3) options at the top of this page should all contain links to the specific sections on this page. In other words, they should act like navigation. |
Please consider #4294 as a starting point, |
This PR was merged into the 2.3 branch. Discussion ---------- Improve cookbook entry for error pages in 2.3~ This PR cherry-picks the improvements from #4293 that apply to 2.3 as well (almost all!). It also addresses some of the considerations in #4181. Commits ------- f74b6f2 Improve cookbook entry for error pages in 2.3~
#4294 has been merged. Let me know if you're still missing anything! |
Imo, we should add some code in the third step to actually show you what's needed for an exception listener. The example from the Security component is a great use case, but the code itself contains a lot of lines, where as you only need some lines of code to get things rolling. |
I've just closed the related PR #5503. This entry does need some work, and the whole thing should be reviewed and updated:
|
Thank you for this issue. |
Hello? This issue is about to be closed if nobody replies. |
I think we can safely close this issue. The page has been revamped, following the changes in exception handling in Symfony (with the introduction of the ErrorHandler component). |
Currently, the doc explains how to overwrite the error page rendered by the controller.
This is fine for apps wanting to make the error page look better by having them consistent with their styles.
However, the exception handling system of Symfony is much more flexible than that. This can be particularly useful if you throw domain-related exceptions in your codebase which should be rendered as client errors rather than a 500 page for instance.
The usage of listeners on the
kernel.exception
event allows to handle this case very easily, and without requiring to use subrequests and a controller. See symfony/symfony#11752 (comment) for the original discussion.As a side note, this is exactly what the Security component does in core for the
Symfony\Component\Security\Core\Exception\AccessDeniedException
.I don't know a public project using this approach (but I'm very far from knowing the codebase all open-source projects based on Symfony). However @weaverryan, I know that KnpLabs used this approach already in one of its project for which I saw the codebase when I was working there. So some of your colleagues should be able to show you this approach at least.
The text was updated successfully, but these errors were encountered: