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

        if (!$this->supports($request)) {
            return;
        }

        $statusCode = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
        $errors     = array();

        switch(true) {

            // validation exception
            case $exception instanceof ValidationException :
                $errors = $this->parseValidationException($exception);
                $statusCode = 400;
            break;

            // other http exceptions
            default:
                $errors = array($exception->getMessage());
        }

        $data = array(
            'code'    => $statusCode,
            'message' => $exception->getMessage(),
            'errors'  => $errors
        );
        if ($this->debug) {
            $data['trace'] = explode("\n", $exception->getTraceAsString());
        }

        $event->setResponse(new JsonResponse($data, $statusCode));
    }