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

Handle too many requests response #303

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/slack.js
Expand Up @@ -59,9 +59,8 @@ export default class SlackData extends EventEmitter {
return channel ? channel.id: null
}

retry (){
let interval = this.interval * 2
setTimeout(this.fetch.bind(this), interval)
retry (delay = this.interval * 2){
setTimeout(this.fetch.bind(this), delay)
this.emit('retry')
}

Expand All @@ -71,6 +70,11 @@ export default class SlackData extends EventEmitter {
return this.retry()
}

// Too Many Requests
if (res.status == 429) {
return this.retry(res.headers['retry-after'] * 1000)
}

let users = res.body.members

if (!users || (users && !users.length)) {
Expand Down