You are here

public static function RequestException::getResponseBodySummary in Lockr 7.3

Get a short summary of the response

Will return `null` if the response is not printable.

Parameters

ResponseInterface $response:

Return value

string|null

1 call to RequestException::getResponseBodySummary()
RequestException::create in vendor/guzzlehttp/guzzle/src/Exception/RequestException.php
Factory method to create a new exception with a normalized error message

File

vendor/guzzlehttp/guzzle/src/Exception/RequestException.php, line 125

Class

RequestException
HTTP Request exception

Namespace

GuzzleHttp\Exception

Code

public static function getResponseBodySummary(ResponseInterface $response) {
  $body = $response
    ->getBody();
  if (!$body
    ->isSeekable()) {
    return null;
  }
  $size = $body
    ->getSize();
  if ($size === 0) {
    return null;
  }
  $summary = $body
    ->read(120);
  $body
    ->rewind();
  if ($size > 120) {
    $summary .= ' (truncated...)';
  }

  // Matches any printable character, including unicode characters:
  // letters, marks, numbers, punctuation, spacing, and separators.
  if (preg_match('/[^\\pL\\pM\\pN\\pP\\pS\\pZ\\n\\r\\t]/', $summary)) {
    return null;
  }
  return $summary;
}