Skip to content

Enforce safe-error message policy on all API routes via errorMessagePolicy #273

@mikewheeleer

Description

@mikewheeleer

Description

src/errors/errorMessagePolicy and safeErrors.ts define safe client messages, but routes registered in router.ts/app.ts may still leak internal details on unhandled errors. Add a centralized error-handling middleware that maps all errors through the policy.

Requirements and context

  • Add a terminal Express error handler that converts any error into an AppError-shaped safe response.
  • Internal details logged (redacted) but never returned; include a correlation ID in responses for support.
  • Acceptance: errorMessagePolicy.integration.test.ts asserts unknown errors, appError.ts errors, and validation errors all return safe bodies with correct status codes.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b security/central-error-handler
  • Implement changes:
    • src/errors/safeErrors.ts
    • Tests: src/errors/errorMessagePolicy.integration.test.ts
    • Docs: docs/API.md
    • Include TSDoc/NatSpec-style doc comments
    • Validate security assumptions (input validation, auth, signature verification, secret redaction, idempotency)

Test and commit

  • Run tests: npm test (coverage: npm run test:ci)
  • Cover edge cases
  • Include test output and security notes in the PR

Example commit message

feat(errors): enforce safe-error policy via central handler

Guidelines

  • Minimum 95% line coverage on new/changed code
  • No secrets in repo; use .env + deployment secrets only
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Assignees

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions