src/Graviton/CoreBundle/Listener/JsonExceptionListener.php
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();

        // Should return a error 400 bad request
        if ($exception instanceof ValidationException
         || $exception instanceof SyntaxErrorException) {
            return;
        }

        // Some Exceptions have status code and if 400 it should be handled by them
        if (method_exists($exception, 'getStatusCode')
            && (400 == (int)$exception->getStatusCode())) {
            return;
        }

        $data = $this->decorateKnownCases($exception);

        if (!is_array($data)) {
            $data = [
                'code' => $exception->getCode(),
                'exceptionClass' => get_class($exception),
                'message' => $exception->getMessage()
            ];

            if ($exception->getPrevious() instanceof \Exception) {
                $data['innerMessage'] = $exception->getPrevious()->getMessage();
            }
        }

        if ($this->logger instanceof Logger) {
            $this->logger->critical($exception);
        }

        $response = new JsonResponse($data);
        $event->setResponse($response);
    }
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $exception = $event->getException();

        // Should return a error 400 bad request
        if ($exception instanceof ValidationException
         || $exception instanceof SyntaxErrorException) {
            return;
        }

        // Some Exceptions have status code and if 400 it should be handled by them
        if (method_exists($exception, 'getStatusCode')
            && (400 == (int)$exception->getStatusCode())) {
            return;
        }

        $data = $this->decorateKnownCases($exception);

        if (!is_array($data)) {
            $data = [
                'code' => $exception->getCode(),
                'exceptionClass' => get_class($exception),
                'message' => $exception->getMessage()
            ];

            if ($exception->getPrevious() instanceof \Exception) {
                $data['innerMessage'] = $exception->getPrevious()->getMessage();
            }
        }

        if ($this->logger instanceof Logger) {
            $this->logger->critical($exception);
        }

        $response = new JsonResponse($data);
        $event->setResponse($response);
    }
public function onKernelException ( GetResponseForExceptionEvent $ event ) { $ exception = $ event -> getException ( ) ; // Should return a error 400 bad request if ( $ exception instanceof ValidationException || $ exception instanceof SyntaxErrorException ) { return ; } // Some Exceptions have status code and if 400 it should be handled by them if ( method_exists ( $ exception , 'getStatusCode' ) && ( 400 == ( int ) $ exception -> getStatusCode ( ) ) ) { return ; } $ data = $ this -> decorateKnownCases ( $ exception ) ; if ( ! is_array ( $ data ) ) { $ data = [ 'code' => $ exception -> getCode ( ) , 'exceptionClass' => get_class ( $ exception ) , 'message' => $ exception -> getMessage ( ) ] ; if ( $ exception -> getPrevious ( ) instanceof \ Exception ) { $ data [ 'innerMessage' ] = $ exception -> getPrevious ( ) -> getMessage ( ) ; } } if ( $ this -> logger instanceof Logger ) { $ this -> logger -> critical ( $ exception ) ; } $ response = new JsonResponse ( $ data ) ; $ event -> setResponse ( $ response ) ; }
Should not handle Validation Exceptions and only service exceptions

@param GetResponseForExceptionEvent $event Sf Event

@return void
Should not handle Validation Exceptions and only service exceptions