You are here

protected function AcquiaContentHubFiltersCommands::fetchFilterInfo in Acquia Content Hub 8.2

Fetches filter info.

Parameters

string $uuid: Cloud filter's UUID.

Return value

array Filter info if filter exists. Otherwise throws exception.

Throws

\Exception

1 call to AcquiaContentHubFiltersCommands::fetchFilterInfo()
AcquiaContentHubFiltersCommands::filterDetails in src/Commands/AcquiaContentHubFiltersCommands.php
Prints filter details.

File

src/Commands/AcquiaContentHubFiltersCommands.php, line 400

Class

AcquiaContentHubFiltersCommands
Drush command to interact with Acquia Content Hub filters.

Namespace

Drupal\acquia_contenthub\Commands

Code

protected function fetchFilterInfo(string $uuid) : array {
  if (!Uuid::isValid($uuid)) {
    $errorMessage = dt('Provided value "{value}" is not a valid UUID.', [
      'value' => $uuid,
    ]);
    throw new \InvalidArgumentException($errorMessage);
  }
  try {
    $client = $this->clientFactory
      ->getClient();
    $info = $client
      ->getFilter($uuid);
  } catch (\Exception $exception) {
    throw $exception;
  }
  if (empty($info)) {
    $errorMessage = dt('Filter with UUID = "{uuid}" does not exist.', [
      'uuid' => $uuid,
    ]);
    throw new \InvalidArgumentException($errorMessage);
  }
  if (isset($info['success'], $info['error']) && !$info['success']) {
    $context = [
      'code' => $info['error']['code'],
      'reason' => $info['error']['message'],
      'id' => $info['request_id'],
    ];
    $errorMessage = dt('Operation failed (code: {code}, Request ID: {id}). {reason}', $context);
    throw new \Exception($errorMessage);
  }
  return $info;
}