You are here

protected function AkamaiClientBase::formatExceptionMessage in Akamai 8.3

Formats a JSON error response into a string.

Parameters

\GuzzleHttp\Exception\RequestException $e: The RequestException containing the JSON error response.

Return value

string The formatted error message as a string.

1 call to AkamaiClientBase::formatExceptionMessage()
AkamaiClientV3::purgeRequest in src/Plugin/Client/AkamaiClientV3.php
Ask the API to purge an object.

File

src/AkamaiClientBase.php, line 448

Class

AkamaiClientBase
Connects to the Akamai EdgeGrid.

Namespace

Drupal\akamai

Code

protected function formatExceptionMessage(RequestException $e) {
  $message = '';

  // Get the full response to avoid truncation.
  // @see https://laracasts.com/discuss/channels/general-discussion/guzzle-error-message-gets-truncated
  if ($e
    ->hasResponse()) {
    $body = $e
      ->getResponse()
      ->getBody();
    $error_detail = Json::decode($body);
    if (is_array($error_detail)) {
      foreach ($error_detail as $key => $value) {
        $message .= "{$key}: {$value} " . PHP_EOL;
      }
    }
  }
  else {
    $message = $e
      ->getMessage();
  }
  return $message;
}