You are here

protected function HttpController::exceptionResponse in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x src/Controller/HttpController.php \Drupal\jsonrpc\Controller\HttpController::exceptionResponse()

Generates the expected response for a given exception.

Parameters

\Drupal\jsonrpc\Exception\JsonRpcException $e: The exception that generates the error response.

int $status: The response HTTP status.

Return value

\Drupal\Core\Cache\CacheableResponseInterface The response object.

1 call to HttpController::exceptionResponse()
HttpController::resolve in src/Controller/HttpController.php
Resolves an RPC request over HTTP.

File

src/Controller/HttpController.php, line 220

Class

HttpController
The main front controller.

Namespace

Drupal\jsonrpc\Controller

Code

protected function exceptionResponse(JsonRpcException $e, $status = Response::HTTP_INTERNAL_SERVER_ERROR) {
  $context = new Context([
    RpcResponseFactory::RESPONSE_VERSION_KEY => $this->handler
      ->supportedVersion(),
    RpcRequestFactory::REQUEST_IS_BATCH_REQUEST => FALSE,
  ]);
  $normalizer = new RpcResponseFactory($this->validator);
  $rpc_response = $e
    ->getResponse();
  $serialized = Json::encode($normalizer
    ->transform([
    $rpc_response,
  ], $context));
  $response = CacheableJsonResponse::fromJsonString($serialized, $status);
  return $response
    ->addCacheableDependency($rpc_response);
}