refactor(shared): extract sanitizeApiError into shared helper - #4532
Conversation
sanitizeApiError was duplicated byte-for-byte in admin.store.js and invitations.store.js, including the leak-prevention regex that strips stack traces and internal paths from user-facing error messages. Two copies of a redaction rule means fixing one can leave the other leaking. Move it to src/lib/helpers/apiError.js (verbatim, same contract) and import it from both stores. Closes #4515
|
Warning Review limit reached
Next review available in: 58 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4532 +/- ##
==========================================
- Coverage 99.57% 99.57% -0.01%
==========================================
Files 36 37 +1
Lines 1427 1422 -5
Branches 448 446 -2
==========================================
- Hits 1421 1416 -5
Misses 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CodeRabbit hit its Pro review-limit (58 min cooldown reported at PR-open time), so per Both independent reviewers returned 0 findings / OK:
CI green: Lint/Unit Tests/Build, E2E Tests, codecov patch + project. |
Summary
sanitizeApiErrorhelper (previously duplicated byte-for-byte inadmin.store.jsandinvitations.store.js) into a new shared module,src/lib/helpers/apiError.js, and imported it from both stores.Scope
lib/helpers(new),modules/admin/stores,modules/invitations/storesnone— pure extraction, no behavior change, no new dependency between storeslowVerbatim-copy contract
The function body (including the leak-prevention regex) is copied verbatim from both original call sites — confirmed byte-identical on baseline before extraction. Nothing in the redaction logic was changed or "improved": same 200-char cap, same internal-marker checks (collection/stack words,
Error:prefix, stack frame, path segment, file-and-line reference), same generic fallback string.Tests
New
src/lib/helpers/tests/apiError.unit.tests.js— one test per redaction arm:Both
admin.storeandinvitations.storeunit suites stay green unchanged (they already exercisedsanitizeApiErrorindirectly through store actions).DoD grep
grep -rn "const sanitizeApiError" srcnow only matches the helper's ownexport constdeclaration.Validation
npm run lintnpm run test:unitnpm run buildGuardrails check
.env*,secrets/**, keys, tokens)Notes for reviewers
admin.store.jsandinvitations.store.json adjacent lines per that issue) — land this first, then rebase 🔧 Single source for the API base URL #4516.