public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request = $event->getRequest();
        $exception = $event->getException();

        if ($request->isXmlHttpRequest()) {
            if ($exception instanceof AccessDeniedException) {
                $token = $this->context->getToken();
                if (!$this->authenticationTrustResolver->isAnonymous($token)) {
                    $event->setResponse(new Response('You haven\'t enough privileges to perform the required action', 403));
                }
            }
        }
    }
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request = $event->getRequest();
        $exception = $event->getException();

        if ($request->isXmlHttpRequest()) {
            if ($exception instanceof AccessDeniedException) {
                $token = $this->context->getToken();
                if (!$this->authenticationTrustResolver->isAnonymous($token)) {
                    $event->setResponse(new Response('You haven\'t enough privileges to perform the required action', 403));
                }
            }
        }
    }
public function onKernelException ( GetResponseForExceptionEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ exception = $ event -> getException ( ) ; if ( $ request -> isXmlHttpRequest ( ) ) { if ( $ exception instanceof AccessDeniedException ) { $ token = $ this -> context -> getToken ( ) ; if ( ! $ this -> authenticationTrustResolver -> isAnonymous ( $ token ) ) { $ event -> setResponse ( new Response ( 'You haven\'t enough privileges to perform the required action' , 403 ) ) ; } } } }
Returns a response when is an ajax request and an AccessDeniedException has been thrown

@param GetResponseForExceptionEvent $event

@api
Returns a response when is an ajax request and an AccessDeniedException has been thrown