Test the error handler, payload limit, and 404 fallback
Description
The final error handler in src/index.ts special-cases entity.too.large into a 413 payload_too_large and otherwise returns a uniform 500 internal_error; the unknown-route middleware returns a structured 404. Only the 404 case is tested in src/health.test.ts. This issue covers the error and limit paths.
Requirements and context
- Repository scope:
Agentpay-Org/Agentpay-backend only.
- Test that a body exceeding the 100 KiB
express.json limit returns 413 payload_too_large with a requestId.
- Test malformed JSON bodies are handled with a structured error (verify the actual status/shape produced).
- Test the unknown-route
404 not_found echoes method + path and a requestId.
- Assert every error response includes
error, message, and requestId keys consistently.
Suggested execution
- Fork the repo and create a branch
git checkout -b test/testing-17-error-handler
- Implement changes
- Write comprehensive tests in: new
src/errors.test.ts using supertest (send an oversized/malformed body).
- Write code in: if malformed-JSON handling is inconsistent, fix it and document the change.
- Add documentation: none beyond test descriptions.
- Add clear test titles.
- Validate security assumptions: error messages do not leak stack traces or internal paths.
- Test and commit
Test and commit
- Run
npm run build, npm test, and npm run lint.
- Cover edge cases: oversized body, invalid JSON, unknown route for several methods.
- Include the full
npm test output in the PR description.
Example commit message
test: cover error handler, payload limit, and 404 fallback
Guidelines
- Minimum 95 percent test coverage for impacted modules.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Test the error handler, payload limit, and 404 fallback
Description
The final error handler in
src/index.tsspecial-casesentity.too.largeinto a413 payload_too_largeand otherwise returns a uniform500 internal_error; the unknown-route middleware returns a structured404. Only the 404 case is tested insrc/health.test.ts. This issue covers the error and limit paths.Requirements and context
Agentpay-Org/Agentpay-backendonly.express.jsonlimit returns413 payload_too_largewith arequestId.404 not_foundechoes method + path and arequestId.error,message, andrequestIdkeys consistently.Suggested execution
git checkout -b test/testing-17-error-handlersrc/errors.test.tsusingsupertest(send an oversized/malformed body).Test and commit
npm run build,npm test, andnpm run lint.npm testoutput in the PR description.Example commit message
test: cover error handler, payload limit, and 404 fallbackGuidelines
Community & contribution rewards