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: correctly assign status code on rate limit error #15435

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

sean-brydon
Copy link
Member

Api middleware returns a 400 no matter what error is thrown. We need to specifically set the response code for middleware

@graphite-app graphite-app bot requested a review from a team June 14, 2024 10:33
@keithwillcode keithwillcode added consumer core area: core, team members only labels Jun 14, 2024
@dosubot dosubot bot added api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working labels Jun 14, 2024
Copy link

vercel bot commented Jun 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Jun 19, 2024 1:52pm
cal ⬜️ Ignored (Inspect) Visit Preview Jun 19, 2024 1:52pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Jun 19, 2024 1:52pm

Copy link

graphite-app bot commented Jun 14, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (06/14/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Comment on lines +19 to +21
} catch (error) {
res.status(429).json({ message: "Rate limit exceeded" });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no return here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about this, what's the outcome of catching the TRPC error sent by checkRateLimitAndThrowError and not throwing again afterward ? we might want to set status and json and then throw the error again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm will try that morgan

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an error in middle ware results in a 500 being thrown - Added tests this approach works as expected

keithwillcode
keithwillcode previously approved these changes Jun 19, 2024
apps/api/v1/lib/helpers/rateLimitApiKey.test.ts Outdated Show resolved Hide resolved
apps/api/v1/lib/helpers/rateLimitApiKey.test.ts Outdated Show resolved Hide resolved
@keithwillcode keithwillcode added this pull request to the merge queue Jun 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 19, 2024
@keithwillcode keithwillcode added this pull request to the merge queue Jun 19, 2024
@keithwillcode keithwillcode added this to the v4.3 milestone Jun 19, 2024
Merged via the queue into main with commit c5a83f4 Jun 19, 2024
24 checks passed
@keithwillcode keithwillcode deleted the fix/api-ratelimit-response-code branch June 19, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api area: API, enterprise API, access token, OAuth 🐛 bug Something isn't working consumer core area: core, team members only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants