-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(utils): Consider 429 responses in transports #5062
Conversation
size-limit report 📦
|
packages/utils/src/ratelimit.ts
Outdated
@@ -43,9 +43,14 @@ export function isRateLimited(limits: RateLimits, category: string, now: number | |||
*/ | |||
export function updateRateLimits( | |||
limits: RateLimits, | |||
headers: Record<string, string | null | undefined>, | |||
newRateLimitParameters: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's type this to be TransportMakeRequestResponse
? Then we can just do a check against headers with an early return, otherwise we know the headers should be defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite get what you mean with the early return.
Do you mean it like this:
if (!headers?.['x-sentry-rate-limits'] && !headers?.['retry-after'] && statusCode === 429) {
updatedRateLimits.all = now + 60 * 1000;
return;
}
Not sure if that is cleaner...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what - ignore me on the headers check. I guess the header items can be null anyway.
I would still use the TransportMakeRequestResponse
type to make things consistent though.
packages/utils/src/ratelimit.ts
Outdated
now: number = Date.now(), | ||
): RateLimits { | ||
const { statusCode, headers } = newRateLimitParameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can do the destructure in the args above.
Fixes rate limiting by conforming to the rate limiting spec: https://develop.sentry.dev/sdk/rate-limiting/#stage-1-parse-response-headers
Ref: https://getsentry.atlassian.net/browse/WEB-908