Skip to content

fix(web): public api errors answer a fixed message unless the error is a public one - #1315

Open
JOY (JOY) wants to merge 1 commit into
devfrom
fix/1310-public-api-error-messages
Open

JOY (JOY) wants to merge 1 commit into
devfrom
fix/1310-public-api-error-messages

Conversation

@JOY

@JOY JOY (JOY) commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1310

What

  • sanitizePublicApiError is an allow-list now: only a PublicApiError (new, in server/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.
  • jsonApiError never 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 plain Error and a TypeError get the fallback, a PublicApiError keeps 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 PublicApiError class 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

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/app/api/reviews/[id]/vote/route.ts Updated the 500 error handler to return a static string instead of calling sanitizePublicApiError, aligning with the new policy that 5xx errors never expose specific messages.
apps/web/src/server/rate/api-handler.ts Introduced PublicApiError class. Modified sanitizePublicApiError to only accept PublicApiError instances (strict allow-list). Updated jsonApiError to bypass sanitization and return the fallback message for any status code >= 500.
apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts Updated tests to verify that generic Error objects are masked, PublicApiError messages 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
Loading

…s a public one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Oct 28, 2026 7:32pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d79af8fa-171d-4542-a8de-260b6901a48b
Commits

Reviewing files that changed from the base of the PR and between 4eca23d and 0f722db.

Files selected for processing: 3
  • apps/web/src/app/api/reviews/[id]/vote/route.ts
  • apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts
  • apps/web/src/server/rate/api-handler.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

dos[bot]
dos Bot approved these changes Oct 28, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏱️ Code Review completed (3 eligible files · 5,273 chars · 4 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 4eca23d / head 0f722db.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

This branch was successfully deployed

1 active deployment
Preview — 0f722dba Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Frontend / Next.js / UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(web): public api errors pass messages through by default

1 participant