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

fix(utils): Consider 429 responses in transports #5062

Merged
merged 6 commits into from
May 11, 2022

Conversation

lforst
Copy link
Member

@lforst lforst commented May 10, 2022

@lforst lforst added this to the 7.0.0 milestone May 10, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 10, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 18.82 KB (-6.55% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 58.66 KB (-9.22% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.57 KB (-6.84% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 52.82 KB (-8.88% 🔽)
@sentry/browser - Webpack (gzipped + minified) 19.38 KB (-16.59% 🔽)
@sentry/browser - Webpack (minified) 61.91 KB (-24.24% 🔽)
@sentry/react - Webpack (gzipped + minified) 19.4 KB (-16.65% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 42.88 KB (-10.77% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 24.48 KB (-6.11% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 23.02 KB (-5.98% 🔽)

@@ -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: {
Copy link
Member

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.

Copy link
Member Author

@lforst lforst May 10, 2022

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...

Copy link
Member

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.

@lforst lforst marked this pull request as ready for review May 10, 2022 19:05
@lforst lforst requested a review from AbhiPrasad May 10, 2022 19:05
@lforst lforst marked this pull request as draft May 10, 2022 19:15
@lforst lforst removed the request for review from AbhiPrasad May 10, 2022 19:15
now: number = Date.now(),
): RateLimits {
const { statusCode, headers } = newRateLimitParameters;
Copy link
Member

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.

@lforst lforst marked this pull request as ready for review May 11, 2022 08:44
@lforst lforst merged commit 5beee11 into 7.x May 11, 2022
@lforst lforst deleted the lforst-429-response-rate-limiting-handling branch May 11, 2022 11:26
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

Successfully merging this pull request may close these issues.

2 participants