question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add 'retryAfter' property to 'Too Many Request' Error

See original GitHub issue

This is a number in the Retry-After header, when the statuscode is 429.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:11

github_iconTop GitHub Comments

7reactions
kauffecupcommented, Aug 22, 2018

This PR https://github.com/thelinmichael/spotify-web-api-node/pull/237 adds the entire headers object to the error, so consumers can take advantage of the retry-after header. For example, could do something like:

  const doRequest = async (args, retries) => {
    try {
      const response = await spotifyApi.getMySavedTracks(args);
      return response;
    } catch (e) {
      if (retries > 0) {
        console.error(e);
        await asyncTimeout(
          e.headers['retry-after'] ?
            parseInt(e.headers['retry-after']) * 1000 :
            RETRY_INTERVAL
        );
        return doRequest(args, retries - 1);
      }
      throw e;
    }
  };

This creates a wrapper around the request and retries it if the request fails

1reaction
jopekcommented, Aug 3, 2018

@gwynnebaer if i see correctly, using superagent-throttle only allows you to throttle all requests, rather than using the Retry-After header.

@settheset chose to at first automatically retry bases on the Retry-After header but reverted it back to passing the headers to the error object. https://github.com/thelinmichael/spotify-web-api-node/blob/master/src/http-manager.js#L88

Passing the header along with the error object allows one to make use of RxJs’ retryWhen operator and supplying the delay operator the Retry-After value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix 429 Too Many Requests Error - Kinsta
The HTTP 429 error is returned when too many requests are made to a page within a short period of time. Find out...
Read more >
Retry-After - HTTP - MDN Web Docs
When sent with a 429 (Too Many Requests) response, this indicates how long to wait before making a new request.
Read more >
Implementing 429 retries and throttling for API rate-limits - Anvil
Learn how to handle 429 Too Many Requests responses when consuming 3rd party APIs.
Read more >
c# - Too many requests exception on HttpWebRequest ...
Add this to your request header: Retry-After: 120. Like this on code : request.Headers.Add("Retry-After", "120");.
Read more >
Error: 429 Too Many Requests — You've been rate limited
While many services will publish their limits like in the GitHub example above, others may include limits as a property on responses, or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found