refactor(errors): harden responses.error/getMessage and sanitize client payloads#3141
Merged
PierreBrisorgueil merged 3 commits intomasterfrom Feb 21, 2026
Merged
refactor(errors): harden responses.error/getMessage and sanitize client payloads#3141PierreBrisorgueil merged 3 commits intomasterfrom
PierreBrisorgueil merged 3 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors shared error helpers to harden the API error payload contract, separating HTTP status from domain error codes and preventing leakage of raw error objects to clients (especially in production).
Changes:
- Hardened
responses.errorto emit a more explicit payload (status+errorCode) and to omit raw serialized error data in production. - Sanitized
errors.getMessagefallback behavior to avoid JSON-stringifying unknown error objects. - Persisted
statusonAppErrorand added unit tests covering the updated helper behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| modules/core/tests/core.unit.tests.js | Adds unit tests for sanitized errors.getMessage and the updated responses.error payload/production behavior. |
| lib/helpers/responses.js | Introduces status normalization, domain errorCode, safe description resolution, and production redaction of raw error payloads. |
| lib/helpers/errors.js | Updates message cleaning and unknown-error fallback to return a safe generic message. |
| lib/helpers/AppError.js | Stores HTTP status on AppError for downstream status resolution consistency. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3141 +/- ##
==========================================
+ Coverage 89.49% 89.85% +0.35%
==========================================
Files 52 52
Lines 1133 1163 +30
Branches 217 233 +16
==========================================
+ Hits 1014 1045 +31
Misses 107 107
+ Partials 12 11 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
responses.errorto produce a safer and more explicit payload contractstatus+errorCode)errors.getMessagestatusonAppErrorfor consistent downstream handlingresponses.erroranderrors.getMessagebehaviorWhy
Current error helpers may leak internal details and make client-side error handling ambiguous. This change standardizes the response shape while preserving backward-compatible keys (
type,message,description, and numericcode).Validation
npx eslint lib/helpers/AppError.js lib/helpers/errors.js lib/helpers/responses.js modules/core/tests/core.unit.tests.jsnpm test -- modules/core/tests/core.unit.tests.js -t "Errors|Responses"Closes #3139