-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathHttpHandlerError.php
More file actions
56 lines (46 loc) · 1.76 KB
/
Copy pathHttpHandlerError.php
File metadata and controls
56 lines (46 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Aws\Handler;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\NetworkException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ResponseException;
use GuzzleHttp\Exception\ResponseTransferException;
use Psr\Http\Message\ResponseInterface;
/**
* @internal
*/
final class HttpHandlerError
{
private const CURLE_RECV_ERROR = 56;
public static function isConnectionError(\Throwable $exception): bool
{
// Guzzle 8: transfer failures have dedicated exception classes.
if ($exception instanceof NetworkException || $exception instanceof ResponseTransferException) {
return true;
}
// Guzzle 7: connection establishment failures use ConnectException.
if ($exception instanceof ConnectException) {
return true;
}
// Guzzle 7: mid-response receive failures identifiable by cURL handler context.
if ($exception instanceof RequestException && is_callable([$exception, 'getHandlerContext'])
) {
$context = $exception->getHandlerContext();
return !empty($context['errno']) && $context['errno'] === self::CURLE_RECV_ERROR;
}
return false;
}
public static function getResponse(\Throwable $exception): ?ResponseInterface
{
// Guzzle 8: response-aware failures expose the response through ResponseException.
if ($exception instanceof ResponseException) {
return $exception->getResponse();
}
// Guzzle 7: RequestException directly carried an optional response.
if ($exception instanceof RequestException && is_callable([$exception, 'getResponse'])
) {
return $exception->getResponse();
}
return null;
}
}