-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 3 Ignored Deployments
|
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. |
} catch (error) { | ||
res.status(429).json({ message: "Rate limit exceeded" }); | ||
} |
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.
no return here?
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.
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
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.
Hmm will try that morgan
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.
Throwing an error in middle ware results in a 500 being thrown - Added tests this approach works as expected
* set status code * Add tests * Update apps/api/v1/lib/helpers/rateLimitApiKey.test.ts * Update apps/api/v1/lib/helpers/rateLimitApiKey.test.ts --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Api middleware returns a 400 no matter what error is thrown. We need to specifically set the response code for middleware