Bolt\EventListener\NotFoundListener::onKernelException PHP Method

onKernelException() public method

Render the not found page if on frontend and http exception
public onKernelException ( GetResponseForExceptionEvent $event )
$event Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();
        if (!$exception instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
            return;
        }
        if ($exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
            return;
        }
        // If $notFoundPage is referencing a template, render it and be done.
        if ($this->render->hasTemplate($this->notFoundPage)) {
            try {
                $this->renderNotFound($event, $this->notFoundPage, []);
            } catch (TwigErrorLoader $e) {
                // Template not found, fall though to see if we can render a
                // record, failing that let the exception handler take over
            }
        }
        // Next try for referencing DB content.
        $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
        if (!$content instanceof Content || empty($content->id)) {
            return;
        }
        $template = $this->templateChooser->record($content);
        $this->renderNotFound($event, $template, $content->getTemplateContext());
    }