I have this in my controller:
if(some stuff) {
throw $this->createNotFoundException('message');
}
When I test it in dev env, I get the Symfony's page telling Exception detected with my text, but I can't test it in prod env :( I run this php app/console cache:clear --env=prod --no-debug
and then replace only in the URL app_dev.php
with app.php
but the toolbar and Symfony's error page stay.
I created this file - app/Resources/TwigBundle/views/Exception/error.html.twig
. So will it be rendered in prod?
This is in it:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>An Error Occurred: {{ status_text }}</title>
</head>
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
</body>
</html>
where should I give values for status_code
and status _text
? Or they are taken from the exception?
So in general what I want to do is when a condition in my contoller`s action is true, mine customized error page to be shown in prod env. Did I make it already, and if not, how to make it and how to see the result in prod env?
A custom 404 page takes away the confusion of not landing on the page they had intended to land on. It lets your user know that there is an error with their request. Perhaps they mistyped the URL, the page is temporarily unavailable, or the page no longer exists.
you can access your detected text with following way:
{{ exception.message }}
I also tried and i noticed that custom error pages placed in app/Resources/TwigBundle/views/Exception/error.html.twig worked only in prod environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With