From 692e9ea52fa0d04a8ae70e387886a80098f24a7f Mon Sep 17 00:00:00 2001 From: Constantine Nathanson <35217733+const-cloudinary@users.noreply.github.com> Date: Tue, 13 May 2025 15:17:34 +0300 Subject: [PATCH] Add support for `429 Too Many Requests` HTTP status code --- src/Api/BaseApiClient.php | 3 ++- src/Api/Utils/HttpStatusCode.php | 10 ++++++++++ tests/Integration/Search/SearchApiTest.php | 19 ------------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Api/BaseApiClient.php b/src/Api/BaseApiClient.php index f6cc08ac..ceb009a9 100644 --- a/src/Api/BaseApiClient.php +++ b/src/Api/BaseApiClient.php @@ -53,7 +53,8 @@ class BaseApiClient HttpStatusCode::FORBIDDEN => NotAllowed::class, HttpStatusCode::NOT_FOUND => NotFound::class, HttpStatusCode::CONFLICT => AlreadyExists::class, - HttpStatusCode::ENHANCE_YOUR_CALM => RateLimited::class, // RFC6585::TOO_MANY_REQUESTS + HttpStatusCode::ENHANCE_YOUR_CALM => RateLimited::class, + HttpStatusCode::TOO_MANY_REQUESTS => RateLimited::class, HttpStatusCode::INTERNAL_SERVER_ERROR => GeneralError::class, ]; diff --git a/src/Api/Utils/HttpStatusCode.php b/src/Api/Utils/HttpStatusCode.php index 7e367745..90970a1d 100644 --- a/src/Api/Utils/HttpStatusCode.php +++ b/src/Api/Utils/HttpStatusCode.php @@ -90,6 +90,16 @@ class HttpStatusCode */ public const ENHANCE_YOUR_CALM = 420; + /** + * The 429 (Too Many Requests) status code indicates the user has sent too + * many requests in a given amount of time ("rate limiting"). + * + * @link https://datatracker.ietf.org/doc/html/rfc6585#section-4 + * + * @var int + */ + public const TOO_MANY_REQUESTS = 429; + /** * The 500 (Internal Server Error) status code indicates that the server * encountered an unexpected condition that prevented it from fulfilling the diff --git a/tests/Integration/Search/SearchApiTest.php b/tests/Integration/Search/SearchApiTest.php index 3532b948..fbd26d73 100644 --- a/tests/Integration/Search/SearchApiTest.php +++ b/tests/Integration/Search/SearchApiTest.php @@ -281,25 +281,6 @@ public function testFindAssetsByGeneralExpression() self::assertValidAsset($result['resources'][0]); } - /** - * Find assets without limiting expression to certain fields but with an underscore in the expression - * Shows results containing the entire expression in any string field - * Shows results containing the entire expression or a part of it (parts are separated by underscore) in public_id - * - * @throws ApiError - */ - public function testFindAssetsByGeneralExpressionWithUnderscore() - { - $result = $this->search - ->expression(self::$MULTI_STRING) - ->maxResults(2) - ->execute(); - - self::assertEquals(2, $result['total_count']); - self::assertCount(2, $result['resources']); - self::assertValidAsset($result['resources'][0]); - } - /** * Find assets with an expression limiting the search expression to certain fields * Shows results containing given text in tags field