PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 trunk, at vendor_prefixed/guzzlehttp/guzzle/src/Exception/RequestException.php

115 lines 5.0 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 * @deprecated since 7.11. Create a RequestException directly instead.
40 */
41 public static function wrapException(\YoastSEO_Vendor\Psr\Http\Message\RequestInterface $request, \Throwable $e) : \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException
42 {
43 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/guzzle', '7.11', '%s::wrapException() is deprecated and will be removed in 8.0. Create a %s directly instead.', self::class, self::class);
44 return $e instanceof \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException ? $e : new \YoastSEO_Vendor\GuzzleHttp\Exception\RequestException($e->getMessage(), $request, null, $e);
45 }
46 /**
47 * Factory method to create a new exception with a normalized error message
48 *
49 * @param RequestInterface $request Request sent
50 * @param ResponseInterface $response Response received
51 * @param \Throwable|null $previous Previous exception
52 * @param array $handlerContext Optional handler context
53 * @param BodySummarizerInterface|null $bodySummarizer Optional body summarizer
54 */
55 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
56 {
57 if (!$response) {
58 return new self('Error completing request', $request, null, $previous, $handlerContext);
59 }
60 $level = (int) \floor($response->getStatusCode() / 100);
61 if ($level === 4) {
62 $label = 'Client error';
63 $className = \YoastSEO_Vendor\GuzzleHttp\Exception\ClientException::class;
64 } elseif ($level === 5) {
65 $label = 'Server error';
66 $className = \YoastSEO_Vendor\GuzzleHttp\Exception\ServerException::class;
67 } else {
68 $label = 'Unsuccessful request';
69 $className = __CLASS__;
70 }
71 $uri = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::redactUserInfo($request->getUri());
72 // Client Error: `GET /` resulted in a `404 Not Found` response:
73 // <html> ... (truncated)
74 $message = \sprintf('%s: `%s %s` resulted in a `%s %s` response', $label, $request->getMethod(), $uri->__toString(), $response->getStatusCode(), $response->getReasonPhrase());
75 $summary = ($bodySummarizer ?? new \YoastSEO_Vendor\GuzzleHttp\BodySummarizer())->summarize($response);
76 if ($summary !== null) {
77 $message .= ":\n{$summary}\n";
78 }
79 return new $className($message, $request, $response, $previous, $handlerContext);
80 }
81 /**
82 * Get the request that caused the exception
83 */
84 public function getRequest() : \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
85 {
86 return $this->request;
87 }
88 /**
89 * Get the associated response
90 */
91 public function getResponse() : ?\YoastSEO_Vendor\Psr\Http\Message\ResponseInterface
92 {
93 return $this->response;
94 }
95 /**
96 * Check if a response was received
97 */
98 public function hasResponse() : bool
99 {
100 return $this->response !== null;
101 }
102 /**
103 * Get contextual information about the error from the underlying handler.
104 *
105 * The contents of this array will vary depending on which handler you are
106 * using. It may also be just an empty array. Relying on this data will
107 * couple you to a specific handler, but can give more debug information
108 * when needed.
109 */
110 public function getHandlerContext() : array
111 {
112 return $this->handlerContext;
113 }
114 }
115