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: add context to rate-limited event #1637

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions docs/_packages/web_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ const token = process.env.SLACK_TOKEN;

const web = new WebClient(token);

web.on(WebClientEvent.RATE_LIMITED, (numSeconds) => {
console.log(`A rate-limiting error occurred and the app is going to retry in ${numSeconds} seconds.`);
web.on(WebClientEvent.RATE_LIMITED, (numSeconds, { url }) => {
console.log(`A rate-limiting error occurred while calling ${url} and the app is going to retry in ${numSeconds} seconds.`);
});
```

Expand Down
8 changes: 4 additions & 4 deletions packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,9 @@ describe('WebClient', function () {
.reply(429, {}, { 'retry-after': 0 });
const client = new WebClient(token, { rejectRateLimitedCalls: true });
client.on('rate_limited', spy);
client.apiCall('method')
client.apiCall('method', { foo: 'bar' })
.catch((err) => {
assert(spy.calledOnceWith(0))
assert(spy.calledOnceWith(0, sinon.match({ url: 'method', body: { foo: 'bar' } })))
scope.done();
done();
});
Expand Down Expand Up @@ -1213,9 +1213,9 @@ describe('WebClient', function () {
.reply(429, {}, { 'retry-after': 0 });
const client = new WebClient(token, { retryConfig: { retries: 0 } });
client.on('rate_limited', spy);
client.apiCall('method')
client.apiCall('method', { foo: 'bar' })
.catch((err) => {
assert(spy.calledOnceWith(0))
assert(spy.calledOnceWith(0, sinon.match({ url: 'method', body: { foo: 'bar' } })))
scope.done();
done();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export class WebClient extends Methods {
if (response.status === 429) {
const retrySec = parseRetryHeaders(response);
if (retrySec !== undefined) {
this.emit(WebClientEvent.RATE_LIMITED, retrySec);
this.emit(WebClientEvent.RATE_LIMITED, retrySec, { url, body });
if (this.rejectRateLimitedCalls) {
throw new AbortError(rateLimitedErrorWithDelay(retrySec));
}
Expand Down