Skip to content

Comments

refactor(errors): harden responses.error/getMessage and sanitize client payloads#3141

Merged
PierreBrisorgueil merged 3 commits intomasterfrom
codex/fix-issue-3139
Feb 21, 2026
Merged

refactor(errors): harden responses.error/getMessage and sanitize client payloads#3141
PierreBrisorgueil merged 3 commits intomasterfrom
codex/fix-issue-3139

Conversation

@PierreBrisorgueil
Copy link
Contributor

Summary

  • harden responses.error to produce a safer and more explicit payload contract
  • separate HTTP status from domain error code semantics (status + errorCode)
  • avoid exposing raw serialized error payloads in production responses
  • sanitize unknown error message fallback in errors.getMessage
  • persist status on AppError for consistent downstream handling
  • add unit test coverage for the new responses.error and errors.getMessage behavior

Why

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 numeric code).

Validation

  • npx eslint lib/helpers/AppError.js lib/helpers/errors.js lib/helpers/responses.js modules/core/tests/core.unit.tests.js
  • npm test -- modules/core/tests/core.unit.tests.js -t "Errors|Responses"

Closes #3139

Copilot AI review requested due to automatic review settings February 21, 2026 18:36
@PierreBrisorgueil PierreBrisorgueil added Fix A bug fix Severity5: access/security Bug qualification labels Feb 21, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.error to emit a more explicit payload (status + errorCode) and to omit raw serialized error data in production.
  • Sanitized errors.getMessage fallback behavior to avoid JSON-stringifying unknown error objects.
  • Persisted status on AppError and 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
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.85%. Comparing base (14f653d) to head (4d33ffa).
⚠️ Report is 5 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings February 21, 2026 18:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@PierreBrisorgueil PierreBrisorgueil merged commit 770ff88 into master Feb 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix A bug fix Severity5: access/security Bug qualification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(errors): harden responses.error/getMessage contract and prevent internal error leakage

1 participant