Skip to content

Added new ErrorController + Preview and enabling there the error render… #12273

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
fabpot opened this issue Sep 5, 2019 · 8 comments
Closed
Labels
ErrorHandler hasPR A Pull Request has already been submitted for this issue.
Milestone

Comments

@fabpot
Copy link
Member

fabpot commented Sep 5, 2019

Q A
Feature PR symfony/symfony#33271
PR author(s) @yceruto
Merged in 4.4
@OskarStark OskarStark added this to the 4.4 milestone Sep 5, 2019
@yceruto
Copy link
Member

yceruto commented Sep 5, 2019

Note: add a section about functional tests that mentions the before/after behavior around testing exceptions.

@javiereguiluz
Copy link
Member

javiereguiluz commented Sep 23, 2019

@yceruto I'm working on this and I'm having lots of problems trying to understand the changes needed in this page: https://symfony.com/doc/current/controller/error_pages.html

Before, things worked like this:

  1. Customize the visible error pages of your site: use Twig template overriding.
  2. View in dev how errors look in prod: use /_error/{code}.{format}
  3. Run custom logic on exceptions: listen to kernel.exception event.
  4. Do advanced stuff with the dev exceptions: use twig.exception_controller to override the default controller.

Now, how do we do those things?

  1. I don't know. The "templates" are hardcoded in the error renderers.
  2. It looks like the URL changed to /{code}.{format}. If this is right, isn't it confusing to not add some prefix like /_error/ in the URL?
  3. Same as before. No changes in this feature.
  4. I don't know. Not possible anymore? The framework.error_controller value is not really used in the default ErrorController, right? (It's only used in the preview() action)

Thanks!

@yceruto
Copy link
Member

yceruto commented Sep 23, 2019

  1. Customize the visible error pages of your site: use Twig template overriding.
  1. I don't know. The "templates" are hardcoded in the error renderers.

If TwigBundle is enabled, same as before, you can create the error pages in:

  • templates/bundles/TwigBundle/Exception/error.html.twig
  • or templates/bundles/TwigBundle/Exception/error404.html.twig

The difference is that now you can't create non-HTML error pages like error.json.twig, so you must define your own JsonErrorRenderer instead.

  1. View in dev how errors look in prod: use /_error/{code}.{format}
  1. It looks like the URL changed to /{code}.{format}. If this is right, isn't it confusing to not add some prefix like /_error/ in the URL?

As before, the path prefix is defined when we import the routing config, see recipe changes symfony/recipes#645

  1. Run custom logic on exceptions: listen to kernel.exception event.
  1. Same as before. No changes in this feature.

No changes.

  1. Do advanced stuff with the dev exceptions: use twig.exception_controller to override the default controller.
  1. I don't know. Not possible anymore? The framework.error_controller value is not really used in the default ErrorController, right? (It's only used in the preview() action)

Yes, it's possible as before, the framework.error_controller config can be used if TwigBundle is not installed or if twig.exception_controller is set to null explicitly. The new one (framework.error_controller) has the same mean. By default the ErrorController is used for both actions: Rendering the error response and Preview the error response in non-debug mode.

@yceruto
Copy link
Member

yceruto commented Sep 23, 2019

  1. View in dev how errors look in prod: use /_error/{code}.{format}
  1. It looks like the URL changed to /{code}.{format}. If this is right, isn't it confusing to not add some prefix like /_error/ in the URL?

As of now, the prefix has double undercore: __error/. That was needed to avoid conflic with the same config in routes/dev/twig.yaml this has been updated and now it works as before.

@dbrekelmans
Copy link
Contributor

I ran into this while upgrading to symfony 5.0. Since the docs haven't been updated yet, it left me very confused until I found this issue. I shall try to open a PR this sunday to hopefully help others who run into the same issue :)

@yceruto
Copy link
Member

yceruto commented Nov 22, 2019

Hello @dbrekelmans, my previous comment is outdated.

I'm sorry, I don't have time to write/fix the documentation, but I can review any PR about it.

Note: There is no such a component ErrorRenderer nor the JsonErrorRenderer service. Now all these features are handled by the new ErrorHandler component. The customization of the Twig-based HTML error pages work as before by installing the TwigBundle and the serializer component (if installed/enabled) will be used for non-HTML error responses.

@dbrekelmans
Copy link
Contributor

dbrekelmans commented Nov 24, 2019

Hi @yceruto,

This was more work than I expected, but I managed to do most of it.
The only thing I'm struggling with is the Overriding the Default ErrorController paragraph in controller/error_pages.rst.

Would you mind if I open a PR with the changes I have so far?
Maybe someone else can jump in and finish the last section.

You can preview my changes here: https://github.com/dbrekelmans/symfony-docs/compare/4.4...dbrekelmans:fix_12273

@yceruto
Copy link
Member

yceruto commented Nov 24, 2019

Yes, please, submit the changes to this repo, so we can review it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ErrorHandler hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

6 participants