User Experience (UX) has become an essential part of web application development. One of the most important elements of UX is to provide comprehensible and helpful error pages in case things don't work as expected.
Developing and designing these error pages in previous Symfony versions was a bit involved because it required to trigger an exception with the exact HTTP code needed and you had to make the exception controller use the right template.
That's why Symfony 2.6 will include a new option to preview error pages.
Specifically, TwigBundle now contains a routing file that you can import from
your routing_dev.yml
file:
1 2 3 4
# app/config/routing_dev.yml
_errors:
resource: "@TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Once these new routes are loaded, you can preview any error page using these special URLs:
http://localhost/app_dev.php/_error/{statusCode}
http://localhost/app_dev.php/_error/{statusCode}.{format}
The statusCode
corresponds to the HTTP Status Code of the error and the
format
option defaults to html
and accepts any valid request format,
such as json
.
To learn more about customizing your error pages, read the revamped cookbook article about How to Customize Error Pages. Now it's time to test this feature and don't forget to leave a link to your beautiful error page in the comments of this article!
Note: this post was mostly written by Matthias Pigulla.
In case you'd like to give this a try: There is still an open PR with a small fix for the case that you're using a custom exception controller: https://github.com/symfony/symfony/pull/12147
Very helpful when designing beautiful excpetion pages. Thanks.
"Sorry, it's broken.. but so pretty!" ;)
Great idea
This is great! We had a very hacky solution, glad to get rid of it!
Useful indead, instead of throwing exceptions by hand, switch the debug flag... It was boring. Ty.
Nice
I just tried this with my brand new project, I get this:
Catchable Fatal Error: Argument 2 passed to Symfony\Bundle\TwigBundle\Controller\ExceptionController::showAction() must be an instance of Symfony\Component\HttpKernel\Exception\FlattenException, instance of Symfony\Component\Debug\Exception\FlattenException given
@Massimiliano Arione, same here.
Seems to be a namespace problem.
You can change it in @TwigBundle/Controller/PreviewErrorController.php line 14, replace "Debug" by "HttpKernel".