0

I have just updated my Symfony 2.7 page to 2.8. Beside Symfony itself a number of other packages (e.g. FOSUserBundle, FOSRestBundle, Doctrine, etc.) have been updated as well.

After the Update my CustomExceptionController does not work any more. Error like 404 or 500 show the default exception page instead of my custom page. Before the Update my CustomExceptionController worked without any problem.

This is the configuration:

// app/config/config.yml
...
twig:
    exception_controller:  app.exception_controller:showAction


// src/MyAppBundle/Resources/config/services.yml
app.exception_controller:
    class: MyAppBundle\Controller\CustomExceptionController
    arguments: ['@twig', '%kernel.debug%', "@translator.default" ]


// src/MyAppBundle/Controller/CustomExceptionController.php
use Symfony\Component\Debug\Exception\FlattenException;    
//use Symfony\Component\HttpKernel\Exception\FlattenException;

class CustomExceptionController extends ExceptionController {   

protected $translator;

public function __construct(\Twig_Environment $twig, $debug, Translator $translator) {
    parent::__construct($twig, $debug);
    $this->translator = $translator;
}

public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) {
    ...
}

The only change in the config of the CustomExceptionController is using

use Symfony\Component\Debug\Exception\FlattenException 

instead of

use Symfony\Component\HttpKernel\Exception\FlattenException

(which is deprecated since Symfony 2.3). However the problem is the same, also when this changed back to the ..\HttpKernel\... class.

As far as I can tell there have been no other changes the the configuration of the CustomExceptionController. The config is exactly the same as in the Symfony docs.

Any idea what might be wrong?

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • If you just want to create a custom error page, did you look at this already? http://symfony.com/doc/2.8/controller/error_pages.html – Tobias Xy Oct 04 '16 at 14:21
  • Yes I did. As you can see I mentioned this link in my question :) As far as I can tell I exactly followed these instructions to create and config my `CustomExceptionController`. Additionally: I already used the `CustomExceptionController` without any problem for several months in Symfony 2.7. The problem showed up after the update to Symfony 2.8. – Andrei Herford Oct 04 '16 at 14:28
  • I assume you already cleaned your cache? If so, what is the value of the "twig.exception_listener.controller" parameter in your service container (should be "app.exception_controller:showAction")? – Tobias Xy Oct 04 '16 at 14:50
  • I do not know `twig.exception_listener.controller`, where do I have to set this value? Do you mean `twig.exception_controller` which has to be specified in `config.yml`? As described in my question this is defined as `app.exception_controller:showAction` – Andrei Herford Oct 04 '16 at 15:31
  • 1
    I think you should have a look at the FOSRestBundle configuration [reference](http://symfony.com/doc/master/bundles/FOSRestBundle/configuration-reference.html), by default it override your custom message on exception. Look at nodes exception_controller, codes, messages, under `exception` – lolmx Oct 04 '16 at 15:48
  • Thanks lolmx, this was indeed the problem. Disabling the FOSRestBundle exception controller solves the problem. However it is necessary to enable the controller to ensure that FOSRestBundle works properly. How to combine these to requirements? I created a new question to solve this: http://stackoverflow.com/questions/39867504 – Andrei Herford Oct 05 '16 at 07:10

0 Answers0