From a0352e8f5174b72475c893151c300a1fc39a8c9d Mon Sep 17 00:00:00 2001 From: Artem Bondarenko Date: Thu, 13 May 2021 21:01:15 +0300 Subject: [PATCH] Support for HTTP 429 Too Many Requests code --- src/Api/HttpApi.php | 2 ++ src/Exception/HttpClientException.php | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index a347c01..d7c28c3 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -99,6 +99,8 @@ abstract class HttpApi throw HttpClientException::conflict($response); case 413: throw HttpClientException::payloadTooLarge($response); + case 429: + throw HttpClientException::tooManyRequests($response); case 500 <= $statusCode: throw HttpServerException::serverError($statusCode); default: diff --git a/src/Exception/HttpClientException.php b/src/Exception/HttpClientException.php index 8067e44..f073f7b 100644 --- a/src/Exception/HttpClientException.php +++ b/src/Exception/HttpClientException.php @@ -88,6 +88,11 @@ final class HttpClientException extends \RuntimeException implements Exception return new self('Payload too large, your total attachment size is too big.', 413, $response); } + public static function tooManyRequests(ResponseInterface $response) + { + return new self('Too many requests.', 429, $response); + } + public static function forbidden(ResponseInterface $response) { $body = $response->getBody()->__toString();