You are here

public static function JsonRpcException::fromPrevious in JSON-RPC 2.x

Same name and namespace in other branches
  1. 8 src/Exception/JsonRpcException.php \Drupal\jsonrpc\Exception\JsonRpcException::fromPrevious()

Constructs a JsonRpcException from an arbitrary exception.

Parameters

\Throwable|\Exception $previous: An arbitrary exception.

mixed $id: The request ID, if available.

string $version: (optional) The JSON-RPC version.

Return value

static

4 calls to JsonRpcException::fromPrevious()
Handler::doRequest in src/Handler.php
Executes an RPC call and returns a JSON-RPC response.
HttpController::getHttpResponse in src/Controller/HttpController.php
Map RPC response(s) to an HTTP response.
HttpController::getRpcRequests in src/Controller/HttpController.php
Get the JSON RPC request objects for the given Request object.
RpcResponseFactory::doTransform in src/Shaper/RpcResponseFactory.php

File

src/Exception/JsonRpcException.php, line 62

Class

JsonRpcException
Custom exception class for the module.

Namespace

Drupal\jsonrpc\Exception

Code

public static function fromPrevious($previous, $id = FALSE, $version = NULL) {
  if ($previous instanceof JsonRpcException) {

    // Ensures that the ID and version context information are set because it
    // might not have been set or accessible at a lower level.
    $response = $previous
      ->getResponse();
    return static::fromError($response
      ->getError(), $response
      ->id() ?: $id, $response
      ->version());
  }
  $error = Error::internalError($previous
    ->getMessage());
  $response = static::buildResponse($error, $id, $version);
  return new static($response, $previous);
}