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
Description
src/errors/errorMessagePolicyandsafeErrors.tsdefine safe client messages, but routes registered inrouter.ts/app.tsmay still leak internal details on unhandled errors. Add a centralized error-handling middleware that maps all errors through the policy.Requirements and context
AppError-shaped safe response.errorMessagePolicy.integration.test.tsasserts unknown errors,appError.tserrors, and validation errors all return safe bodies with correct status codes.Suggested execution
git checkout -b security/central-error-handlersrc/errors/safeErrors.tssrc/errors/errorMessagePolicy.integration.test.tsdocs/API.mdTest and commit
npm test(coverage:npm run test:ci)Example commit message
Guidelines
.env+ deployment secrets only