You are here

public static function RequestException::create in Auth0 Single Sign On 8.2

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

1 call to RequestException::create()
Middleware::httpErrors in vendor/guzzlehttp/guzzle/src/Middleware.php
Middleware that throws exceptions for 4xx or 5xx responses when the "http_error" request option is set to true.

File

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

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 = (int) floor($response
    ->getStatusCode() / 100);
  if ($level === 4) {
    $label = 'Client error';
    $className = ClientException::class;
  }
  elseif ($level === 5) {
    $label = 'Server error';
    $className = ServerException::class;
  }
  else {
    $label = 'Unsuccessful request';
    $className = __CLASS__;
  }
  $uri = $request
    ->getUri();
  $uri = static::obfuscateUri($uri);

  // Client Error: `GET /` resulted in a `404 Not Found` response:
  // <html> ... (truncated)
  $message = sprintf('%s: `%s %s` resulted in a `%s %s` response', $label, $request
    ->getMethod(), $uri, $response
    ->getStatusCode(), $response
    ->getReasonPhrase());
  $summary = static::getResponseBodySummary($response);
  if ($summary !== null) {
    $message .= ":\n{$summary}\n";
  }
  return new $className($message, $request, $response, $previous, $ctx);
}