Skip to content

chore(backend): add contract tests for errorHandler mapping to http status codes#278

Merged
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
drips-projects:test/error-handler-contract
Apr 23, 2026
Merged

chore(backend): add contract tests for errorHandler mapping to http status codes#278
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
drips-projects:test/error-handler-contract

Conversation

@Joeloo1

@Joeloo1 Joeloo1 commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Description

Implement comprehensive contract tests for the errorHandler middleware to ensure correct mapping of error classes to HTTP status codes. This PR also includes security enhancements and robustness improvements for error identification.

Closes #258

Changes

  • Security: Masked internal error messages in production for non-AppError types in src/middleware/errorHandler.ts.
  • Tests: Extended src/middleware/errorHandler.test.ts with explicit contract tests for all error subclasses and a production environment suite.
  • Robustness: Improved isAppError in src/errors/index.ts to use a brand property, ensuring consistency across module instances.

Test Output

PASS src/middleware/errorHandler.test.ts
Error Handler
✓ should handle AppError with correct response shape
✓ should handle generic Error with default values
...
✓ map ForbiddenError to 403
✓ map NotFoundError to 404
✓ map PaymentRequiredError to 402
✓ map TooManyRequestsError to 429
Error Handler - Production Environment
✓ should mask generic error message in production
✓ should NOT mask AppError messages in production

Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total

Security & Data Integrity Notes

  • Assumption: AppError subclasses are intended for user-facing messages and are safe to expose in production.
  • Assurances: Generic errors are now masked with a generic message in production to prevent leakage of infrastructure details. Full stack traces are preserved in server-side logs for debugging.

@drips-wave

drips-wave Bot commented Apr 23, 2026

Copy link
Copy Markdown

@Joeloo1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me greatest0fallt1me merged commit a5b422a into CalloraOrg:main Apr 23, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: add contract tests for errorHandler mapping to HTTP status codes

2 participants