Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatically retry rate-limited requests #319

Merged
merged 5 commits into from
Aug 25, 2023
Merged

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Aug 23, 2023

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds automatic retry support when Prismic Rest API V2 returns a "429: Too many requests" error response.

The 429 error response can be returned if the API rate limit is exceeded. As of this PR, the API has a limit of 200 requests per second.

@prismicio/client will automatically retry those requests after enough time has ellapsed to avoid the rate limit. The retry will be transparent from client code, except for the extra wait time.

Code using @prismicio/client does not need to change to take advantage of the automatic retry feature.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🦔

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2023

Codecov Report

Merging #319 (e7ed465) into master (af6a593) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##           master     #319   +/-   ##
=======================================
  Coverage   99.96%   99.96%           
=======================================
  Files          50       50           
  Lines        6049     6087   +38     
  Branches      294      301    +7     
=======================================
+ Hits         6047     6085   +38     
  Misses          2        2           
Files Changed Coverage Δ
src/createClient.ts 100.00% <100.00%> (ø)

@angeloashmore angeloashmore marked this pull request as draft August 23, 2023 21:36
Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

src/createClient.ts Show resolved Hide resolved
@angeloashmore angeloashmore marked this pull request as ready for review August 25, 2023 18:28
@angeloashmore angeloashmore changed the title feat: automatically retry requests with a 429: Too many requests API error response feat: automatically retry rate-limited requests Aug 25, 2023
@angeloashmore angeloashmore merged commit e0c8c49 into master Aug 25, 2023
12 checks passed
@angeloashmore angeloashmore deleted the aa/rate-limit branch August 25, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants