bundle/EventListener/LegacyResponseListener.php
public function onKernelResponse(FilterResponseEvent $event)
    {
        $routeName = $event->getRequest()->attributes->get('_route');
        if ($routeName !== FallbackRouter::ROUTE_NAME) {
            return;
        }

        $response = $event->getResponse();
        if (!$response instanceof LegacyResponse) {
            return;
        }

        if (!$this->legacyMode && (int) $response->getStatusCode() === Response::HTTP_NOT_FOUND) {
            $moduleResult = $response->getModuleResult();
            $exception = new NotFoundHttpException(
                isset($moduleResult['errorMessage']) ?
                    $moduleResult['errorMessage'] :
                    'Not Found'
            );

            $exception->setOriginalResponse($response);

            throw $exception;
        }
    }
public function onKernelResponse(FilterResponseEvent $event)
    {
        $routeName = $event->getRequest()->attributes->get('_route');
        if ($routeName !== FallbackRouter::ROUTE_NAME) {
            return;
        }

        $response = $event->getResponse();
        if (!$response instanceof LegacyResponse) {
            return;
        }

        if (!$this->legacyMode && (int) $response->getStatusCode() === Response::HTTP_NOT_FOUND) {
            $moduleResult = $response->getModuleResult();
            $exception = new NotFoundHttpException(
                isset($moduleResult['errorMessage']) ?
                    $moduleResult['errorMessage'] :
                    'Not Found'
            );

            $exception->setOriginalResponse($response);

            throw $exception;
        }
    }
Converts the legacy 404 response to proper Symfony exception.


@param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException