code: public function createJsonResponseFromException(\Exception $exception, JsonRequest $jsonRequest = null)
      {
          $jsonResponse = new JsonResponse();
  
          if ($exception instanceof Exceptions\ErrorException) {
              $jsonResponse->setErrorCode(0 !== $exception->getCode() ? $exception->getCode() : -32603);
              $jsonResponse->setErrorMessage(!empty($exception->getMessage()) ? $exception->getMessage() : 'Internal error');
              $jsonResponse->setErrorData($exception->getData());
          } else {
              $jsonResponse->setErrorCode(0 !== $exception->getCode() ? $exception->getCode() : -32603);
              $jsonResponse->setErrorMessage(!empty($exception->getMessage()) ? $exception->getMessage() : 'Internal error');
          }
  
          if ($jsonRequest) {
              $jsonResponse->setId($jsonRequest->getId());
          }
  
          return $jsonResponse;
      }
docs: Create new JsonResponse from exception.
  
  @param \Exception       $exception
  @param null|JsonRequest $jsonRequest
  
  @return JsonResponse