Throw a too many redirects exception for a request
RequestInterface $request Request:
TooManyRedirectsException when too many redirects have been issued
protected function throwTooManyRedirectsException(RequestInterface $request) {
$responses = array();
// Create a nice message to use when throwing the exception that shows each request/response transaction
do {
$response = $request
->getResponse();
$responses[] = '> ' . $request
->getRawHeaders() . "\n\n< " . $response
->getRawHeaders();
$request = $response
->getPreviousResponse() ? $response
->getPreviousResponse()
->getRequest() : null;
} while ($request);
$transaction = implode("* Sending redirect request\n", array_reverse($responses));
throw new TooManyRedirectsException("Too many redirects were issued for this transaction:\n{$transaction}");
}