21 private $handlerContext;
27 \Exception $previous =
null,
28 array $handlerContext = []
32 ? $response->getStatusCode()
34 parent::__construct($message, $code, $previous);
35 $this->request = $request;
36 $this->response = $response;
37 $this->handlerContext = $handlerContext;
65 public static function create(
68 \Exception $previous =
null,
73 'Error completing request',
81 $level = (int) floor($response->getStatusCode() / 100);
83 $label =
'Client error';
84 $className = ClientException::class;
85 } elseif ($level === 5) {
86 $label =
'Server error';
87 $className = ServerException::class;
89 $label =
'Unsuccessful request';
90 $className = __CLASS__;
94 $uri = static::obfuscateUri($uri);
99 '%s: `%s %s` resulted in a `%s %s` response',
103 $response->getStatusCode(),
104 $response->getReasonPhrase()
107 $summary = static::getResponseBodySummary($response);
109 if ($summary !==
null) {
110 $message .=
":\n{$summary}\n";
113 return new $className($message, $request, $response, $previous, $ctx);
127 return \GuzzleHttp\Psr7\get_message_body_summary($response);
137 private static function obfuscateUri(UriInterface $uri)
139 $userInfo = $uri->getUserInfo();
141 if (
false !== ($pos = strpos($userInfo,
':'))) {
142 return $uri->withUserInfo(substr($userInfo, 0, $pos),
'***');
155 return $this->request;
165 return $this->response;
175 return $this->response !==
null;
190 return $this->handlerContext;