src/Listener/ExceptionListener.php
private function handleNativeError(GetResponseForExceptionEvent $event)
    {
        if (true === $this->debug) {
            return;
        }

        if (true === $this->status) {
            return;
        }

        $this->status = true;

        $exception = $event->getException();
        $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;

        $cmsManager = $this->cmsManagerSelector->retrieve();

        if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) {
            return;
        }

        if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) {
            return;
        }

        if (!$this->hasErrorCode($statusCode)) {
            return;
        }

        $message = sprintf('%s: %s (uncaught exception) at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());

        $this->logException($exception, $exception, $message);

        try {
            $page = $this->getErrorCodePage($statusCode);

            $cmsManager->setCurrentPage($page);

            if (null !== $page->getSite()->getLocale() && $page->getSite()->getLocale() !== $event->getRequest()->getLocale()) {
                // Compare locales because Request returns the default one if null.

                // If 404, LocaleListener from HttpKernel component of Symfony is not called.
                // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale.
                // So in order to translate messages, force here the locale with the site.
                $event->getRequest()->setLocale($page->getSite()->getLocale());
            }

            $response = $this->pageServiceManager->execute($page, $event->getRequest(), [], new Response('', $statusCode));
        } catch (\Exception $e) {
            $this->logException($exception, $e);

            $event->setException($e);
            $this->handleInternalError($event);

            return;
        }

        $event->setResponse($response);
    }
private function handleNativeError(GetResponseForExceptionEvent $event)
    {
        if (true === $this->debug) {
            return;
        }

        if (true === $this->status) {
            return;
        }

        $this->status = true;

        $exception = $event->getException();
        $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;

        $cmsManager = $this->cmsManagerSelector->retrieve();

        if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) {
            return;
        }

        if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) {
            return;
        }

        if (!$this->hasErrorCode($statusCode)) {
            return;
        }

        $message = sprintf('%s: %s (uncaught exception) at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine());

        $this->logException($exception, $exception, $message);

        try {
            $page = $this->getErrorCodePage($statusCode);

            $cmsManager->setCurrentPage($page);

            if (null !== $page->getSite()->getLocale() && $page->getSite()->getLocale() !== $event->getRequest()->getLocale()) {
                // Compare locales because Request returns the default one if null.

                // If 404, LocaleListener from HttpKernel component of Symfony is not called.
                // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale.
                // So in order to translate messages, force here the locale with the site.
                $event->getRequest()->setLocale($page->getSite()->getLocale());
            }

            $response = $this->pageServiceManager->execute($page, $event->getRequest(), [], new Response('', $statusCode));
        } catch (\Exception $e) {
            $this->logException($exception, $e);

            $event->setException($e);
            $this->handleInternalError($event);

            return;
        }

        $event->setResponse($response);
    }
private function handleNativeError ( GetResponseForExceptionEvent $ event ) { if ( true === $ this -> debug ) { return ; } if ( true === $ this -> status ) { return ; } $ this -> status = true ; $ exception = $ event -> getException ( ) ; $ statusCode = $ exception instanceof HttpExceptionInterface ? $ exception -> getStatusCode ( ) : 500 ; $ cmsManager = $ this -> cmsManagerSelector -> retrieve ( ) ; if ( $ event -> getRequest ( ) -> get ( '_route' ) && ! $ this -> decoratorStrategy -> isRouteNameDecorable ( $ event -> getRequest ( ) -> get ( '_route' ) ) ) { return ; } if ( ! $ this -> decoratorStrategy -> isRouteUriDecorable ( $ event -> getRequest ( ) -> getPathInfo ( ) ) ) { return ; } if ( ! $ this -> hasErrorCode ( $ statusCode ) ) { return ; } $ message = sprintf ( '%s: %s (uncaught exception) at %s line %s' , \ get_class ( $ exception ) , $ exception -> getMessage ( ) , $ exception -> getFile ( ) , $ exception -> getLine ( ) ) ; $ this -> logException ( $ exception , $ exception , $ message ) ; try { $ page = $ this -> getErrorCodePage ( $ statusCode ) ; $ cmsManager -> setCurrentPage ( $ page ) ; if ( null !== $ page -> getSite ( ) -> getLocale ( ) && $ page -> getSite ( ) -> getLocale ( ) !== $ event -> getRequest ( ) -> getLocale ( ) ) { // Compare locales because Request returns the default one if null. // If 404, LocaleListener from HttpKernel component of Symfony is not called. // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale. // So in order to translate messages, force here the locale with the site. $ event -> getRequest ( ) -> setLocale ( $ page -> getSite ( ) -> getLocale ( ) ) ; } $ response = $ this -> pageServiceManager -> execute ( $ page , $ event -> getRequest ( ) , [ ] , new Response ( '' , $ statusCode ) ) ; } catch ( \ Exception $ e ) { $ this -> logException ( $ exception , $ e ) ; $ event -> setException ( $ e ) ; $ this -> handleInternalError ( $ event ) ; return ; } $ event -> setResponse ( $ response ) ; }
Handles a native error.

@param GetResponseForExceptionEvent $event

@throws mixed
Handles a native error .