|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Riot\Exception; |
| 6 | + |
| 7 | +use Psr\Http\Message\ResponseInterface; |
| 8 | + |
| 9 | +final class RateLimitExceededException extends RiotApiException |
| 10 | +{ |
| 11 | + private int $retryAfter; |
| 12 | + |
| 13 | + private string $rateLimitType; |
| 14 | + private string $appRateLimit; |
| 15 | + private string $appRateLimitCount; |
| 16 | + private string $methodRateLimit; |
| 17 | + private string $methodRateLimitCount; |
| 18 | + |
| 19 | + public function __construct( |
| 20 | + string $message, |
| 21 | + int $retryAfter, |
| 22 | + string $rateLimitType, |
| 23 | + string $appRateLimit, |
| 24 | + string $appRateLimitCount, |
| 25 | + string $methodRateLimit, |
| 26 | + string $methodRateLimitCount |
| 27 | + ) { |
| 28 | + parent::__construct($message); |
| 29 | + $this->retryAfter = $retryAfter; |
| 30 | + $this->rateLimitType = $rateLimitType; |
| 31 | + $this->appRateLimit = $appRateLimit; |
| 32 | + $this->appRateLimitCount = $appRateLimitCount; |
| 33 | + $this->methodRateLimit = $methodRateLimit; |
| 34 | + $this->methodRateLimitCount = $methodRateLimitCount; |
| 35 | + } |
| 36 | + |
| 37 | + public function getRetryAfter(): int |
| 38 | + { |
| 39 | + return $this->retryAfter; |
| 40 | + } |
| 41 | + |
| 42 | + public function getRateLimitType(): string |
| 43 | + { |
| 44 | + return $this->rateLimitType; |
| 45 | + } |
| 46 | + |
| 47 | + public function getAppRateLimit(): string |
| 48 | + { |
| 49 | + return $this->appRateLimit; |
| 50 | + } |
| 51 | + |
| 52 | + public function getAppRateLimitCount(): string |
| 53 | + { |
| 54 | + return $this->appRateLimitCount; |
| 55 | + } |
| 56 | + |
| 57 | + public function getMethodRateLimit(): string |
| 58 | + { |
| 59 | + return $this->methodRateLimit; |
| 60 | + } |
| 61 | + |
| 62 | + public function getMethodRateLimitCount(): string |
| 63 | + { |
| 64 | + return $this->methodRateLimitCount; |
| 65 | + } |
| 66 | + |
| 67 | + public static function createFromResponse(ResponseInterface $response): self |
| 68 | + { |
| 69 | + return new self( |
| 70 | + 'Rate limit exceeded', |
| 71 | + (int) $response->getHeader('retry-after')[0], |
| 72 | + $response->getHeader('x-rate-limit-type')[0], |
| 73 | + $response->getHeader('x-app-rate-limit')[0], |
| 74 | + $response->getHeader('x-app-rate-limit-count')[0], |
| 75 | + $response->getHeader('x-method-rate-limit')[0], |
| 76 | + $response->getHeader('x-method-rate-limit-count')[0], |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments