Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Document the handling of exceptions with listeners #4181

Copy link
Copy link
Closed
@stof

Description

@stof
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalledactionableClear and specific issues ready for anyone to take them.Clear and specific issues ready for anyone to take them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.