You are here

protected function HttpServiceApiWrapperBase::call in HTTP Client Manager 8.2

Call REST web services.

Parameters

string $command: The command name.

array $args: The command arguments.

mixed $fallback: The fallback value in case of exception.

Return value

\GuzzleHttp\Command\ResultInterface The service result.

1 call to HttpServiceApiWrapperBase::call()
HttpServiceApiWrapperBase::callByRequest in src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperBase.php
Call by Request.

File

src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperBase.php, line 102

Class

HttpServiceApiWrapperBase
Class HttpServiceApiWrapperBase.

Namespace

Drupal\http_client_manager\Plugin\HttpServiceApiWrapper

Code

protected function call($command, array $args = [], $fallback = []) {
  $httpClient = $this
    ->gethttpClient();
  $http_method = $httpClient
    ->getCommand($command)
    ->getHttpMethod();
  try {
    return $httpClient
      ->call($command, $args);
  } catch (CommandException $e) {
    $this
      ->logError($e);
    if (strtolower($http_method) != 'get') {
      $fallback = [
        'error' => TRUE,
        'message' => $e
          ->getMessage(),
      ];
    }
    return new Result($fallback);
  }
}