fix(api): guard Upstash rate-limit failures on non-keeper routes - #641
Conversation
|
@QwinDivy is attempting to deploy a commit to the Collins' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@QwinDivy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
collinsezedike
left a comment
There was a problem hiding this comment.
The fix itself is correct: all 6 remaining routes get the same try/catch → log → 503 pattern already used in the keeper routes, and the new regression test covers it.
CI fails on three checks though:
- PR Title: "Guard Upstash rate-limit failures on non-keeper routes" doesn't follow the conventional-commit format (
type(scope): subject) this repo requires. Please rename to something likefix(api): guard Upstash rate-limit failures on non-keeper routes. - Commit Messages: same root cause, the commit header has no type prefix (
type may not be empty,subject may not be empty). - Lint & Typecheck:
prettier --checkfails onapi/__tests__/handlers.test.ts. Runpnpm formatand push.
The PR body's Summary and Test plan sections are also still empty (the raw template). Please fill those in per CONTRIBUTING.md before this is ready for merge.
One thing worth considering, not blocking: the try/catch/503 block is now duplicated verbatim across 8 call sites. Might be worth pushing that into checkRateLimit itself so a future change to the guard doesn't need to be copy-edited into 8 files by hand, but that's a design call, not something I'd hold up this fix for.
dee5979 to
ebc08e2
Compare
close #639
Summary
checkRateLimit's call to Upstash (ratelimit.limit(ip)) was unguarded on 6 routes (tx/deposit,tx/withdraw,tx/submit,tx/add-trustline,positions/[publicKey],vaults/index,vaults/[vaultId]), unlike the keeper routes which already catch this failure and return a clean 503.503 {"error": "Rate limiter unavailable; refusing to run"}instead of crashing unguarded on a transient Upstash timeout.Test plan
pnpm lint && pnpm typecheckpass locallypnpm test(api package): 46/46 pass, including the new regression test asserting a 503 on a rejectedcheckRateLimit