public static function BadResponseException::factory

Factory method to create a new response exception based on the response code.

Parameters

RequestInterface $request Request:

Response $response Response received:

Return value

BadResponseException

1 call to BadResponseException::factory()
Request::onRequestError in drupal/core/vendor/guzzle/http/Guzzle/Http/Message/Request.php
Default method that will throw exceptions if an unsuccessful response is received.

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Exception/BadResponseException.php, line 26

Class

BadResponseException
Http request exception thrown when a bad response is received

Namespace

Guzzle\Http\Exception

Code

public static function factory(RequestInterface $request, Response $response) {
  if ($response
    ->isClientError()) {
    $label = 'Client error response';
    $class = __NAMESPACE__ . '\\ClientErrorResponseException';
  }
  elseif ($response
    ->isServerError()) {
    $label = 'Server error response';
    $class = __NAMESPACE__ . '\\ServerErrorResponseException';
  }
  else {
    $label = 'Unsuccessful response';
    $class = __CLASS__;
    $e = new self();
  }
  $message = $label . PHP_EOL . implode(PHP_EOL, array(
    '[status code] ' . $response
      ->getStatusCode(),
    '[reason phrase] ' . $response
      ->getReasonPhrase(),
    '[url] ' . $request
      ->getUrl(),
    '[request] ' . (string) $request,
    '[response] ' . (string) $response,
  ));
  $e = new $class($message);
  $e
    ->setResponse($response);
  $e
    ->setRequest($request);
  return $e;
}