PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / guzzle / src / Exception / RequestException.php

RequestException.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at vendor_prefixed/guzzlehttp/guzzle/src/Exception/RequestException.php

112 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YoastSEO_Vendor\GuzzleHttp\Exception;
4
5 use YoastSEO_Vendor\GuzzleHttp\BodySummarizer;
6 use YoastSEO_Vendor\GuzzleHttp\BodySummarizerInterface;
7 use YoastSEO_Vendor\Psr\Http\Client\RequestExceptionInterface;
8 use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
9 use YoastSEO_Vendor\Psr\Http\Message\ResponseInterface;
10 /**
11 * HTTP Request exception
12 */
13 class RequestException extends \YoastSEO_Vendor\GuzzleHttp\Exception\TransferException implements \YoastSEO_Vendor\Psr\Http\Client\RequestExceptionInterface
14 {
15 /**
16 * @var RequestInterface
17 */
18 private $request;
19 /**
20 * @var ResponseInterface|null
21 */
22 private $response;
23 /**
24 * @var array
25 */
26 private $handlerContext;
27 public function __construct(string $message, \YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, ?\YoastSEO_Vendor\Psr\Http\Message\ResponseInterface $response = null, ?\Throwable $previous = null, array $handlerContext = [])
28 {
29 // Set the code of the exception if the response is set and not future.
30 $code = $response ? $response->getStatusCode() : 0;
31 parent::__construct($message, $code, $previous);
32 $this->request = $request;
33 $this->response = $response;
34 $this->handlerContext = $handlerContext;
35 }
36 /**
37 * Wrap non-RequestExceptions with a RequestException
38 */
39 public static function wrapException(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, \Throwable $e) : \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException
40 {
41 return $e instanceof \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException ? $e : new \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException($e->getMessage(), $request, null, $e);
42 }
43 /**
44 * Factory method to create a new exception with a normalized error message
45 *
46 * @param RequestInterface $request Request sent
47 * @param ResponseInterface $response Response received
48 * @param \Throwable|null $previous Previous exception
49 * @param array $handlerContext Optional handler context
50 * @param BodySummarizerInterface|null $bodySummarizer Optional body summarizer
51 */
52 public static function create(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, ?\YoastSEO_Vendor\Psr\Http\Message\ResponseInterface $response = null, ?\Throwable $previous = null, array $handlerContext = [], ?\YoastSEO_Vendor\GuzzleHttp\BodySummarizerInterface $bodySummarizer = null) : self
53 {
54 if (!$response) {
55 return new self('Error completing request', $request, null, $previous, $handlerContext);
56 }
57 $level = (int) \floor($response->getStatusCode() / 100);
58 if ($level === 4) {
59 $label = 'Client error';
60 $className = \YoastSEO_Vendor\GuzzleHttp\Exception\ClientException::class;
61 } elseif ($level === 5) {
62 $label = 'Server error';
63 $className = \YoastSEO_Vendor\GuzzleHttp\Exception\ServerException::class;
64 } else {
65 $label = 'Unsuccessful request';
66 $className = __CLASS__;
67 }
68 $uri = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::redactUserInfo($request->getUri());
69 // Client Error: `GET /` resulted in a `404 Not Found` response:
70 // <html> ... (truncated)
71 $message = \sprintf('%s: `%s %s` resulted in a `%s %s` response', $label, $request->getMethod(), $uri->__toString(), $response->getStatusCode(), $response->getReasonPhrase());
72 $summary = ($bodySummarizer ?? new \YoastSEO_Vendor\GuzzleHttp\BodySummarizer())->summarize($response);
73 if ($summary !== null) {
74 $message .= ":\n{$summary}\n";
75 }
76 return new $className($message, $request, $response, $previous, $handlerContext);
77 }
78 /**
79 * Get the request that caused the exception
80 */
81 public function getRequest() : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
82 {
83 return $this->request;
84 }
85 /**
86 * Get the associated response
87 */
88 public function getResponse() : ?\YoastSEO_Vendor\Psr\Http\Message\ResponseInterface
89 {
90 return $this->response;
91 }
92 /**
93 * Check if a response was received
94 */
95 public function hasResponse() : bool
96 {
97 return $this->response !== null;
98 }
99 /**
100 * Get contextual information about the error from the underlying handler.
101 *
102 * The contents of this array will vary depending on which handler you are
103 * using. It may also be just an empty array. Relying on this data will
104 * couple you to a specific handler, but can give more debug information
105 * when needed.
106 */
107 public function getHandlerContext() : array
108 {
109 return $this->handlerContext;
110 }
111 }
112