-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpStatusBasedFailureDetector.php
54 lines (48 loc) · 1.46 KB
/
HttpStatusBasedFailureDetector.php
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
<?php
declare(strict_types = 1);
namespace Interrupt\FailureDetectors;
use Interrupt\Contracts\FailureDetectorInterface;
use Psr\Http\Message\ResponseInterface;
/**
* Detects failure based on HTTP Response Status Code (5xx range)
*/
class HttpStatusBasedFailureDetector implements FailureDetectorInterface {
/**
* @var int[]
*/
protected array $failureCodes;
/**
* @link https://github.com/ackintosh/ganesha/blob/master/src/Ganesha/HttpClient/RestFailureDetector.php#L20-L41
*/
public const FAILURE_CODES = [
500, // Internal Server Error
501, // Not Implemented
502, // Bad Gateway
503, // Service Unavailable
504, // Gateway Timeout
505, // HTTP Version Not Supported
506, // Variant Also Negotiates
507, // Insufficient Storage
508, // Loop Detected
509, // Bandwidth Limit Exceeded
510, // Not Extended
511, // Network Authentication Required
520, // Origin Error
521, // Origin Declined Request
522, // Connection Timed Out
523, // Proxy Declined Request
524, // Timeout Occurred
525, // SSL Handshake Failed
526, // Invalid SSL Certificate
527 // Railgun Error
];
/**
* @param int[] $failureCodes
*/
public function __construct(array $failureCodes = []) {
$this->failureCodes = $failureCodes ?: self::FAILURE_CODES;
}
public function isFailure(ResponseInterface $response): bool {
return in_array($response->getStatusCode(), $this->failureCodes, true);
}
}