public function createHttpResponseFromException(\Exception $exception)
    {
        $httpResponse = HttpResponse::create();
        $json = [];
        $json['jsonrpc'] = '2.0';
        $json['error'] = [];

        if ($exception instanceof Exceptions\ErrorException) {
            $json['error']['code'] = $exception->getCode();
            $json['error']['message'] = $exception->getMessage();

            if ($exception->getData()) {
                $json['error']['data'] = $exception->getData();
            }

            $json['id'] = $exception->getId();
        } else {
            $json['error']['code'] = -32603;
            $json['error']['message'] = 'Internal error';
            $json['id'] = null;
        }

        $httpResponse->headers->set('Content-Type', 'application/json');
        $httpResponse->setContent(\json_encode($json));
        $httpResponse->setStatusCode($this->errorCode);

        $this->dispatch(
            Event\HttpResponseEvent::EVENT,
            new Event\HttpResponseEvent($httpResponse)
        );

        return $httpResponse;
    }