Added code for handling rate limits
I'm checking for status code 429 in the handleReponse() method, which indicates that the rate limit has been reached, and simply delaying and then repeating the request after the allotted time from the 'X-Retry-After' header returned in the response, up to a maximum of 3 times for now. This has been tested locally using a script that generates over 9000 getTime() requests using OAuth authentication on a development store.
Coverage decreased (-1.4%) to 67.764% when pulling 4e2d57af4382516023122d8db5f5928725eb8585 on nortronthered:feature/handle-api-rate-limits into 71c6d49be1d68445801f0f4acddd82e7e815086c on bigcommerce:master.
Coverage decreased (-1.4%) to 67.764% when pulling 4e2d57af4382516023122d8db5f5928725eb8585 on nortronthered:feature/handle-api-rate-limits into 71c6d49be1d68445801f0f4acddd82e7e815086c on bigcommerce:master.
Coverage decreased (-1.4%) to 67.764% when pulling 4e2d57af4382516023122d8db5f5928725eb8585 on nortronthered:feature/handle-api-rate-limits into 71c6d49be1d68445801f0f4acddd82e7e815086c on bigcommerce:master.
@nortronthered please see our adjustments to rate limiting headers here:
https://developer.bigcommerce.com/api/#rate-limits-oauth
This may change your approach, hopefully for the better!
I'd feel more comfortable with this if there was a setting to turn this on or off.
Why have this not merged yet?
A couple of reasons:
- There's an outstanding comment about removing the IDE-specific ignores.
- There needs to be a toggle to turn this auto-retry behavior off.
- We've made changes to how the rate limiting headers behave, which should help improve this code.