You are here

public function ApigeeEdgeManagementCliService::handleHttpClientExceptions in Apigee Edge 8

Print out helpful information to user running command when error happens.

Parameters

\GuzzleHttp\Exception\TransferException $exception: The exception thrown.

\Symfony\Component\Console\Style\StyleInterface $io: The IO interface of the CLI tool calling the method.

callable $t: The translation function akin to t().

string $url: The url being connected to.

string $org: The organization to connect to.

string $email: The email of an Edge user with org admin role to make Edge API calls.

3 calls to ApigeeEdgeManagementCliService::handleHttpClientExceptions()
ApigeeEdgeManagementCliService::createEdgeRoleForDrupal in src/Command/Util/ApigeeEdgeManagementCliService.php
Create role in Apigee Edge for Drupal to use for Edge connection.
ApigeeEdgeManagementCliService::isValidEdgeCredentials in src/Command/Util/ApigeeEdgeManagementCliService.php
Validate the Apigee Edge org connection settings.
ApigeeEdgeManagementCliService::setDefaultPermissions in src/Command/Util/ApigeeEdgeManagementCliService.php
Set default permissions for a role used for Drupal portal connections.

File

src/Command/Util/ApigeeEdgeManagementCliService.php, line 311

Class

ApigeeEdgeManagementCliService
Defines an interface for Edge connection classes.

Namespace

Drupal\apigee_edge\Command\Util

Code

public function handleHttpClientExceptions(TransferException $exception, StyleInterface $io, callable $t, string $url, string $org, string $email) : void {

  // Display error message.
  $io
    ->error($t('Error connecting to Apigee Edge. :exception_message', [
    ':exception_message' => $exception
      ->getMessage(),
  ]));

  // Add a note to common situations on what could be wrong.
  switch ($exception
    ->getCode()) {
    case 0:
      $io
        ->note($t('Your system may not be able to connect to :url.', [
        ':url' => $url,
      ]));
      return;
    case 401:
      $io
        ->note($t('Your username or password is invalid.'));
      return;
    case 403:
      $io
        ->note($t('User :email may not have the orgadmin role for Apigee Edge org :org.', [
        ':email' => $email,
        ':org' => $org,
      ]));
      return;
    case 302:
      $io
        ->note($t('Edge endpoint gives a redirect response, is the url :url does not seem to be a valid Apigee Edge endpoint.', [
        ':url' => $url,
      ]));
      return;
  }
}