Skip to content

refactor(filters): standardize error payloads for all error types - #475

Merged
Cjay-Cyber-2 merged 1 commit into
ASTROIDX556:mainfrom
ezechinonyelumvivian-create:refactor/296-standardize-error-payloads
Oct 22, 2026
Merged

Cjay-Cyber-2 merged 1 commit into
ASTROIDX556:mainfrom
ezechinonyelumvivian-create:refactor/296-standardize-error-payloads

Conversation

@ezechinonyelumvivian-create

@ezechinonyelumvivian-create ezechinonyelumvivian-create commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Standardizes every API error response on one RFC 9457 problem-details payload, including failures raised before a request reaches a controller.

Why

The global filter already emitted the envelope for application errors, but Nest forwards pre-route failures (body-parser rejecting malformed JSON, oversized payloads, middleware next(err) calls) as plain Express errors. Those bypassed the mapping, so an oversized body surfaced as 500 INTERNAL_ERROR and clients had to handle a second error shape.

What changed

  • Extracted error classification and serialization (domain exceptions, Prisma, HttpException, request-id resolution, problem builder) into problem-details.util.ts — a single source of truth for the schema.
  • Added resolution for the Express err.status / err.statusCode shape: client errors keep their real status and mapped code (413 Payload Too Large, 415, 403, …), while unexpected 5xx errors keep the generic detail so nothing internal is exposed.
  • Added unit and real-HTTP integration tests, including a production-mode assertion that responses never carry a stack trace.
  • Documented that pre-route rejections use the same envelope.

Related issue

Closes #296
closes #288
closes #289
closes #290

Checklist

  • npm run build passes
  • npm test passes (1903 tests)
  • npm run lint passes
  • npm run typecheck passes
  • No secrets added to tracked files
  • PR description explains the why, not just the what

Errors forwarded by Nest from outside its request pipeline (body-parser
rejections, middleware next(err) calls) kept their raw Express shape, so an
oversized body surfaced as a 500 and clients saw more than one error schema.
Extract the problem-details mapping into one module used by the global filter
and resolve the Express-style status/statusCode shape to the same RFC 9457
envelope.

Closes ASTROIDX556#296

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Cjay-Cyber-2
Cjay-Cyber-2 merged commit 61ee645 into ASTROIDX556:main Oct 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants