protected function HttpController::exceptionResponse in JSON-RPC 2.x
Same name and namespace in other branches
- 8 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.
2 calls to HttpController::exceptionResponse()
- HttpController::preflight in src/
Controller/ HttpController.php - Resolves a preflight request for an RPC request.
- HttpController::resolve in src/
Controller/ HttpController.php - Resolves an RPC request over HTTP.
File
- src/
Controller/ HttpController.php, line 282
Class
- HttpController
- The main front controller.
Namespace
Drupal\jsonrpc\ControllerCode
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);
}