Repository navigation
Conversation
…s a public one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 19 seconds. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #1310
What
sanitizePublicApiErroris an allow-list now: only aPublicApiError(new, inserver/rate/api-handler.ts) passes its message, and still not one that looks internal or is over 240 characters. Any other error answers with the route's fixed message.jsonApiErrornever puts an error's message in a 5xx body.POST /api/reviews/[id]/vote: the 500 path answers its fixed message; the 400 vote rejections answer their fixed messages too (the 403 not-eligible and 429 rate-limit answers are unchanged).No route passed an error to a 4xx
jsonApiError, so no client-facing validation message changes.Tests
core-rate-architecture.test.ts: a plainErrorand aTypeErrorget the fallback, aPublicApiErrorkeeps its message, an internal-looking public message is still masked, a 5xx with a public error gets the fixed message.Checks
pnpm --filter web test,tsc --noEmit, eslint, prettier: green locally.🤖 Generated with Claude Code
📌 TL;DR
This PR hardens the public API error handling by introducing a
PublicApiErrorclass to strictly allow-list client-facing messages, preventing the leakage of internal database or system errors. It also ensures that all 5xx responses return a generic fallback message regardless of the underlying error type.🎯 Type of Change
🔍 Changes Walkthrough
apps/web/src/app/api/reviews/[id]/vote/route.tssanitizePublicApiError, aligning with the new policy that 5xx errors never expose specific messages.apps/web/src/server/rate/api-handler.tsPublicApiErrorclass. ModifiedsanitizePublicApiErrorto only acceptPublicApiErrorinstances (strict allow-list). UpdatedjsonApiErrorto bypass sanitization and return the fallback message for any status code >= 500.apps/web/src/server/rate/__tests__/core-rate-architecture.test.tsErrorobjects are masked,PublicApiErrormessages are preserved (unless they look internal), and 5xx responses always use the fallback message.📊 Architectural Flow
flowchart TD A[API Request] --> B{Error Occurred?} B -- No --> C[Success Response] B -- Yes --> D{Status Code?} D -- 5xx --> E[Return Fixed Fallback Message] D -- 4xx --> F{Is Error Instance of PublicApiError?} F -- No --> G[Return Fixed Fallback Message] F -- Yes --> H{Message Looks Internal or Too Long?} H -- Yes --> G H -- No --> I[Return Sanitized Public Message] E --> J[JSON Response] G --> J I --> J