Contributed by
webfactory GmbH
in #12096.
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 theformat
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.