New in Symfony 2.6: Error page previews
October 23, 2014 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
"Sorry, it's broken.. but so pretty!" ;)
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
Seems to be a namespace problem.
You can change it in @TwigBundle/Controller/PreviewErrorController.php line 14, replace "Debug" by "HttpKernel".