You are here

public static function RequestException::create in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/Exception/RequestException.php \GuzzleHttp\Exception\RequestException::create()

Factory method to create a new exception with a normalized error message

Parameters

RequestInterface $request Request:

ResponseInterface $response Response received:

\Exception $previous Previous exception:

array $ctx Optional handler context.:

Return value

self

File

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

Class

RequestException
HTTP Request exception

Namespace

GuzzleHttp\Exception

Code

public static function create(RequestInterface $request, ResponseInterface $response = null, \Exception $previous = null, array $ctx = []) {
  if (!$response) {
    return new self('Error completing request', $request, null, $previous, $ctx);
  }
  $level = floor($response
    ->getStatusCode() / 100);
  if ($level == '4') {
    $label = 'Client error response';
    $className = __NAMESPACE__ . '\\ClientException';
  }
  elseif ($level == '5') {
    $label = 'Server error response';
    $className = __NAMESPACE__ . '\\ServerException';
  }
  else {
    $label = 'Unsuccessful response';
    $className = __CLASS__;
  }
  $message = $label . ' [url] ' . $request
    ->getUri() . ' [http method] ' . $request
    ->getMethod() . ' [status code] ' . $response
    ->getStatusCode() . ' [reason phrase] ' . $response
    ->getReasonPhrase();
  return new $className($message, $request, $response, $previous, $ctx);
}