Skip to content

Redact unexpected errors and harden the request contract - #1

Merged
hugobessa merged 1 commit into
mainfrom
feat/contract-hardening
Oct 9, 2026
Merged

hugobessa merged 1 commit into
mainfrom
feat/contract-hardening

Conversation

@hugobessa

@hugobessa hugobessa commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Brings this implementation back in line with the shared contract in vintasend-ts-api, and stops logging whole errors.

Logging (PHI)

Unexpected errors were logged with logger.exception: the message, the traceback and the concrete path, any of which can quote notification content, recipients or context values. They are now one redacted line: the error class, a request id, the method and the route pattern. This matches the templates management API.

  • The 500 carries the request id in X-Request-Id.
  • Django's duplicate django.request record is suppressed.
  • VINTASEND_UNHANDLED_ERROR_HANDLER (optional, may be async) takes over reporting for an error tracker with its own scrubbing. If it raises, the redacted line is logged instead.
  • A system check fails manage.py check when that handler cannot be imported.

Contract

  • Request bodies: a request declaring application/json (or application/*+json) must carry a valid JSON object. A request declaring no media type or another one counts as an omitted body when empty, and is a 400 otherwise. Malformed JSON is answered in the error envelope, no longer as Ninja's bare {"detail": …}.
  • Every 400 carries details.issues.
  • hasMore means the next page has a row.
  • FORBIDDEN (403): new code, declared on every authenticated route. This server does not produce it yet.
  • openapi.yaml is byte-identical to vintasend-ts-api's again; it had drifted.

Tests

  • test_contract.py pins every route's declared statuses to openapi.yaml.
  • The test client fails any test that receives a 4xx its route does not declare.

Testing

  • 136 tests pass, with ruff and mypy clean.
  • The 17 new tests fail against the previous code. The redacted-logging test, run against the old code, prints the synthetic patient string in the logged traceback.

Release

Behaviour change for clients sending bodies without Content-Type: application/json, and for deployments relying on tracebacks in the logs; see the 3.3.0 release notes in the vintasend repository.

Related PRs

Python

TypeScript

Python: merge the two API PRs, then the release notes. TypeScript: merge the package PRs, then vintasoftware/vintasend-ts#15, then run the release.

🤖 Generated with Claude Code

- Unexpected errors were logged with logger.exception: message, traceback and
  concrete path, which can quote notification content and context values.
  They are now one redacted line (class, request id, method, route pattern),
  with X-Request-Id on the 500, Django's duplicate record suppressed, and an
  optional VINTASEND_UNHANDLED_ERROR_HANDLER checked at startup.
- Request bodies follow the contract's media-type rule, and malformed JSON is
  answered in the error envelope instead of Ninja's bare {"detail": ...}.
- Every 400 carries details.issues.
- hasMore means the next page has a row.
- FORBIDDEN (403) is a new code, declared on every authenticated route.
- openapi.yaml is byte-identical to vintasend-ts-api's again, and a test pins
  the routes' declared statuses to it; the test client fails any test that
  receives a 4xx its route does not declare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant