Conversation
Register a Fastify plugin that catches unhandled route errors and returns structured JSON responses. PpgErrors map to their code/message, validation errors return VALIDATION_ERROR, and unexpected errors return INTERNAL_ERROR without leaking stack traces in production. Closes #87
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR introduces a centralized error handling module for Fastify that registers a global error handler plugin. It implements HTTP status mapping for custom error codes, distinguishes between PpgError, validation errors, and unhandled errors, and provides environment-aware error responses. Two new Fastify dependencies have been added to support this functionality. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
- P1: Replace exitCode-as-HTTP-status with explicit code-to-status lookup map (httpStatusByCode). PpgError.exitCode is a CLI concept, not an HTTP one — WORKTREE_NOT_FOUND→404, MANIFEST_LOCK→409, etc. - P2: Remove unused vi import, use vi.stubEnv for safe env mutation in tests with vi.unstubAllEnvs in afterEach - P2: Add await app.ready() before inject in all tests - P3: Fix test naming to follow 'given X, should Y' convention - P3: Add async route handler test case - Add httpStatusForPpgError unit tests for lookup table coverage
Summary
src/server/error-handler.ts) that registers a globalsetErrorHandleras a safety net for unhandled route errorsPpgErrorinstances map to theircodeandmessagewith appropriate HTTP status{ error: { code: "VALIDATION_ERROR", message } }{ error: { code: "INTERNAL_ERROR", message } }— stack traces and internal details are suppressed in production (NODE_ENV=production)fastify-plugin(viafp()) so the handler is registered at the root scope, not encapsulatedTest plan
npm testpassesCloses #87
Summary by CodeRabbit
New Features
Tests
Chores