When my app couldn't connect to the database it throws a Fatal Error message :
so how to show a custom error page for this error like 404 page error ?
is there any configuration to do in symfony config.yml ?
thank you !
You can display custom 404, 403, 500 errors if you will override your default Twig-based template. For this purpose you should create folder "TwigBundle" in your app/Resources directory and emulate the following structure:
That should help. The mechanism is the same as for 404 page. This also can help you to extend my answer: Symfony documentation
You can also create Service and mark it as exception listener. In this service you can log your exception and display any response you like. You can actually do anything that can be done within Symfony Service.
More details:
Symfony documentation
My previous answer on this topic
Related
I have two differents pages getting the same error in my symfony3.4 application.
It is a detail page of an entity, it is working most of the time but sometimes and I don't know what is triggering the error, I get a 404 error and I can see my route truncated in the error.
The route is : {base_url}/app_dev.php/stock/model/{id}/detail
On some of my resources, the error message is :
It seems to happend on specific entities but I have no clues about what could possibly trigger that kinds of error.
Any idea of what I could investigate to debug ?
-- EDIT --
It seems that the route is working fine using {base_url}/web/app_dev.php , the problem appears when the route has no /web in dev mode ({base_url}/app_dev.php)
Sometimes Symfony3 throught a 404 error in dev mode without the /web . It is a server configuration matter. Check https://symfony.com/doc/3.4/setup/web_server_configuration.html for more informations
I am getting the following error messages in my logging after a recent release:
The controller for path '/cspuat/node_modules/angular/angular.min.js.map' was not found or does not implement IController.
It would appear that somehow a request is being made to the server from the source map file.
I have tried adding the folling IngoreRoute
routes.IgnoreRoute("{resource}.map/{*pathInfo}");
But the error is still happening.
I'm using Symfony2.4, and my question is:
- Symfony always tries exception and shows its error page
- But if my web faces 500 error, I want it to show default error page of nginx.
Can anybody help me?
Thanks in advance!
The kernel is catching exception like 500, or 404...
By default, he call TwigBundle:Exception:show controller, that will choose the template to use.
Create this folder.
app/Resources/TwigBundle/views/Exception
And add twig templates with the same name as TwigBundle's templates. They will override the default template.
Following the lead of the cookbook:
http://symfony.com/doc/master/cookbook/controller/error_pages.html
The custom error pages are never rendered in production. If I understand correctly the problem is shared by many on the web. Does anyone know of a method that really works?
You can create custom exception listener which will for example render some template.
See the similiar post: Symfony2 Custom Error Exception Listener - Rendering templates or passing to a controller
I'm trying to create a custom 404 page in my admin when something goes wrong and a 404 is thrown.
In my settings.yml file in:
apps/admin/config/settings.yml
I have the following:
all:
.actions:
# 404 module/action
error_404_module: common
error_404_action: error404
I have the module 'common' in my modules folder and I've defined an action called:
executeError404()
and also the template:
error404Success.php
But for some reason, this action never seems to get called as I've tried an exit(); but it still calls the default 404 error message that symfony throws.
Does anyone have any ideas?
Thanks
The custom 404 page doesn't show when in dev mode. If you change your front controller to the production one you should see it if it's configured correctly.
So rather than going to frontend_dev.php got to frontend.php or index.php depending on your setup.