Skip to content

Add test coverage for the global error handler, 413 payload limit, and 404 fallback #47

Description

@mikewheeleer

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.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions