Symfony 5.1 Subscriber "An error occurred while loading the web debug toolbar."

I’m creating configured maintenance page.
I created Subscriber

    public function onKernelRequest(RequestEvent $event)
        $maintenance = $this->container->hasParameter('maintenance') ? $this->container->getParameter('maintenance') : false;
        $underMaintenanceUntil = $this->container->hasParameter('underMaintenanceUntil') ? $this->container->getParameter('underMaintenanceUntil') : false;

        if (!$event->isMasterRequest()){

        $debug = in_array($this->container->get('kernel')->getEnvironment(), ['test','dev']);
        $uri = $event->getRequest()->getRequestUri();

        if ($uri == '/login' || $uri == '/logout') {


        if ($maintenance && !$debug && !$this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
            $engine = $this->container->get('twig');

            $content = $engine->render('pages/maintenance.html.twig', array('underMaintenanceUntil' => $underMaintenanceUntil));
            $event->setResponse(new Response($content, 503));

And profiler bar doesn’t work. I get

An error occurred while loading the web debug toolbar.

In log:

[Application] Oct 5 08:24:41 |INFO | REQUES Matched route "_wdt".
method="GET" request_uri="https://localhost:8001/_wdt/914ef7"
[Application] Oct 5 08:24:41 |CRITICA| REQUES Uncaught PHP Exception
"The token storage contains no authentication token. One possible
reason may be that there is no firewall configured for this URL." at
line 52

And even if I type /login page I get the same error. Should’t this if ($uri == '/login' || $uri == '/logout') {return;} prevents to not executing further code if it is login uri?

This $this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN') generates my errors because in dev firewall there is no auth token. I can check if token exists but why previous if doesn’t work?.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *