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

Rate limiting. #15

Open
LiamKarlMitchell opened this issue Nov 21, 2018 · 1 comment
Open

Rate limiting. #15

LiamKarlMitchell opened this issue Nov 21, 2018 · 1 comment

Comments

@LiamKarlMitchell
Copy link

The Toggl API docs mention.
For rate limiting we have implemented a Leaky bucket. When a limit has been hit the request will get a HTTP 429 response and it's the task of the client to sleep/wait until bucket is empty. Limits will and can change during time, but a safe window will be 1 request per second. Limiting is applied per api token per IP, meaning two users from the same IP will get their rate allocated separately.

I have not encountered this limit yet, however I wonder if it could be useful to implement an option to throttle rapid requests? Or would the view be that this be implemented in application code not the module?

Kind regards,

@LiamKarlMitchell
Copy link
Author

LiamKarlMitchell commented Dec 2, 2018

Okay, I made many updates in quick succession and get this 429 Too Many Requests error.

I think it should delay and retry when encountered.

code:429
data:<html>\r\n<head><title>429 Too Many Requests</title></head>\r\n<body>\r\n<center><h1>429 Too Many Requests</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
isOperational:true
stack:"Error: Unknown API error\n    at Request.onresponse [as _callback] client.js:138:16)
function delay (ms, result) {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      resolve(result)
    }, ms)
  })
}

if (errorUpdate.code === 429) {
  await delay(1000)
  // How to retry somewhere in client.js 's onresponse
}

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

No branches or pull requests

1 participant