-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Ease development for error pages #7446
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
the first suggestion is a duplicate of #1486 For the second suggestion, I'm against adding routes triggering errors. |
@stof Regarding my motivation for the second suggestion: We have Designers/Frontend-Engineers developing our error pages, that do not know where or how to throw an exception... Might be an organizational problem though... |
Couldn't a bundle be created to provide your second suggestion? Load it only in dev and possibly test env. Create a controller to throw exceptions as described by @stof (/_exception/{statusCode} throws the provided status code exception). |
@aderuwe Creating a new bundle only for that might be overkill. Why not in TwigBundle? Of course that test routes / controller would only be available in dev mode... |
Might be a route contained in Symfony's TwigBundle that you can add to your routing_development.yml (for example) file if you want to test production-like exceptions unter /_exception/{status}/... while in kernel.debug mode. Whether or not the exception is rendered as error* or exception* could be triggered by the route as well, since the Request is already passed into the Controller. (Probably makes no sense to see the exception* page for an intentionally-thrown exception, though.) |
I find the idea of providing special routes in development and/or test environment good. |
Maybe https://packagist.org/packages/webfactory/exceptions-bundle is helpful for folks here? Some initial docs are available at http://inside.webfactory.de/de/blog/symfony2-exception-handling-and-custom-error-pages-explained.html. |
… need to set kernel.debug=false (mpdude) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #3577). Discussion ---------- Development of custom error pages is impractical if you need to set kernel.debug=false Also see symfony/symfony#7446 and symfony/symfony#1486 Commits ------- 6aa90e0 Use WebfactoryExceptionsBundle instead of webfactory/exceptions-bundle 2fee263 Update error_pages.rst 435019c Point out the difference between error and exception pages. 2194607 Add a pointer to webfactory/exceptions-bundle which helps with development of custom error pages.
…de (mpdude) This PR was squashed before being merged into the 2.6-dev branch (closes #12096). Discussion ---------- Add an action to show *error* pages in kernel.debug mode | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7446, #1486, #11327 | License | MIT | Doc PR | symfony/symfony-docs#4293 See #7446 for the initial reasoning. In short, add to your `routing_development.yml` file the following ```yaml _errors: resource: "@TwigBundle/Resources/config/routing/errors.xml" prefix: /_error ``` Then you can use `http://localhost/app_dev.php/_error/xxx` to preview the HTML *error* page that the default `ExceptionController` (from `TwigBundle`) would pick for the XXX status code. You can also use `http://localhost/app_dev.php/_error/xxx.{some_format}` to show error pages for other formats than HTML, most notably `txt`. Note that the status code will be 500 for all exceptions [that do not implement `HttpExceptionInterface`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/Exception/FlattenException.php#L47). ##### Want to test with a custom exception? ~~Folks might want to display (part of) the exception even on error pages and thus need to work with generic (own) exceptions.~~ ~~They could write an arbitrary controller and throw their exception there. By default, the `ExceptionController` would be used to handle this, only that it would not show *error* pages in `kernel.debug` mode.~~ ~~Thus, a simple public setter to change the `debug` flag after construction could help. Do we want to add that as well?~~ If you want to test error pages with your own exceptions, * create a subclass of `ExceptionController` * set the protected `debug` flag to false * register it as twig.exception_controller in the config * throw your custom exception from any controller. That should give you the error page also in `kernel.debug` mode. ##### To-Do - [x] Update docs - [x] Add route in symfony/symfony-default Commits ------- 66ed177 Add an action to show *error* pages in kernel.debug mode
It is currently quiet hard to test modifications within custom error pages. It involves the following steps:
When in development mode the exception controller defaults to use a template called "exception_". In production it searches for "error_". So you either need to switch to production locally or rename your template temporarily. When switching to production locally Twig will start to cache the compiled templates. So you even need to clear the cache after each modification or deactivate caching in your Twig configuration. It is ugly anyway.
To actually see the error page, an exception has to be thrown. This might still be easy for 404 exceptions (http://localhost/app.php/there/is/no/page/here...), but is more difficult for other exception types (e.g. 403, 500).
Suggestion:
It would be even nicer if calling the test route would implicitly switch to "production" templates without having to reconfigure TwigBundle.
I have already had a look into TwigBundle and could provide a PR if you like the idea.
Or am I overseeing something existing?
The text was updated successfully, but these errors were encountered: