Skip to content

fix(api): return JSON 4xx errors for malformed bodies and invalid query parameters - #1764

Merged
1nonlypiece merged 2 commits into
Disciplr-Org:mainfrom
Viccodes11:fix/api-json-4xx-errors
Oct 24, 2026
Merged

1nonlypiece merged 2 commits into
Disciplr-Org:mainfrom
Viccodes11:fix/api-json-4xx-errors

Conversation

@Viccodes11

Copy link
Copy Markdown
Contributor

Closes #1686

Summary of Changes

  • Query Parameter Validation: Added apilib/query.mjs with validators for status, creator, and vaultId. Applied them across GET /vaults, GET /transactions, and GET /stats. Array query params and invalid formats now cleanly return 400 JSON errors naming the invalid parameter.
  • JSON Error Handling Middleware: Added a 4-argument Express error middleware mapping body-parser errors (entity.parse.failed -> 400 Malformed JSON body, entity.too.large -> 413, unsupported charset/encoding -> 415) and safe 500 JSON responses without stack or DB error leakage.
  • Media Type & Method Enforcement: Required Content-Type: application/json for POST routes (returning 415 JSON) and added 405 Method Not Allowed handling with Allow header for known paths.
  • OpenAPI Schema Updates: Documented 400 responses on GET /vaults, GET /transactions, and GET /stats.
  • Test Suite: Added unit tests for query validators (apilib/__tests__/query.test.mjs) and integration tests (api/__tests__/errors.test.mjs) testing all acceptance criteria and parameterized fuzzing across all OpenAPI paths.

@1nonlypiece
1nonlypiece merged commit d18c514 into Disciplr-Org:main Oct 24, 2026
2 of 5 checks passed
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] Return JSON 4xx errors for malformed bodies and invalid query parameters instead of HTML and 500s

2 participants