Repository navigation
Expand file tree
/
Copy pathStreamRateLimitException.php
More file actions
68 lines (63 loc) · 2.17 KB
/
Copy pathStreamRateLimitException.php
File metadata and controls
68 lines (63 loc) · 2.17 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
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace GetStream\Exceptions;
/**
* Thrown when the Stream API returns HTTP 429. Carries the parsed
* `Retry-After` header (integer seconds; `null` if header missing or
* unparseable).
*
* Auto-retry is off by default. Enable the opt-in policy with
* `ClientBuilder::retry(new RetryConfig(enabled: true))`; it retries only
* GET/HEAD requests, honoring this exception's `getRetryAfter()` value.
* Compose your own strategy from `getRetryAfter()` if you need anything
* richer.
*/
class StreamRateLimitException extends StreamApiException
{
private ?int $retryAfter;
/**
* @param string $message APIError.message
* @param int $statusCode HTTP status (typically 429)
* @param int $code APIError.code
* @param array<string, string> $exceptionFields APIError.exception_fields
* @param bool $unrecoverable APIError.unrecoverable
* @param string $rawResponseBody Raw HTTP response body
* @param string|null $moreInfo APIError.more_info
* @param mixed $details APIError.details
* @param int|null $retryAfter Parsed `Retry-After` header, seconds
* @param \Throwable|null $previous Cause-chain link
*/
public function __construct(
string $message,
int $statusCode,
int $code = 0,
array $exceptionFields = [],
bool $unrecoverable = false,
string $rawResponseBody = '',
?string $moreInfo = null,
mixed $details = null,
?int $retryAfter = null,
?\Throwable $previous = null,
) {
parent::__construct(
$message,
$statusCode,
$code,
$exceptionFields,
$unrecoverable,
$rawResponseBody,
$moreInfo,
$details,
$previous,
);
$this->retryAfter = $retryAfter;
}
/**
* Parsed `Retry-After` response header in integer seconds.
* Returns `null` when the header is absent or unparseable.
*/
public function getRetryAfter(): ?int
{
return $this->retryAfter;
}
}