ADR-0005 — Return RFC 7807 Problem Details for every error
Status
Accepted. Migrated from the previous bespoke shape during the REST API hardening work; the OpenAPI spec and the full httptest suite were updated in the same change.
Context
The service originally returned errors as:
{"error": "planned heads exceeds installed stations"}
That shape has three concrete problems.
- The only machine-readable signal is the HTTP status code, and it is
ambiguous. This service maps thirteen distinct domain errors to
400and seven to409. A client that needs to distinguish "the WIP limit is reached, back off and retry" from "this unit was already completed, stop retrying" — both409— has nothing to branch on but the prose inerror. - Clients end up parsing prose. The natural workaround is
if body.error.contains("WIP limit"), which turns an error message into an API contract that cannot be reworded. - It is a bespoke shape in a platform of five services. Every client needs per-service error handling for no benefit.
RFC 7807 exists for exactly this: a
standard application/problem+json body with a stable type URI identifying
the category, a fixed title, the duplicated status, a per-occurrence
detail and an instance.
Decision
We will return RFC 7807 application/problem+json for every 4xx and 5xx
response, with a stable per-category type URI.
HTTP/1.1 409 Conflict
Content-Type: application/problem+json
{
"type": "https://errors.wes-work-planning.warehouse-systems.dev/wip-limit-reached",
"title": "Release-fed pool WIP limit reached",
"status": 409,
"detail": "release-fed pool WIP limit reached",
"instance": "/paths/pick-a/work-releases"
}
typeis the contract. Namespaced per service so URIs never collide across the platform. It does not resolve to a real page — RFC 7807 explicitly permits that, and promising a resolvable URI would create a documentation site that must never 404. Clients match ontype, never ondetail.titleis fixed per category;detailmay vary per occurrence. The split is what makestype/titlesafe to depend on while leavingdetailfree to be helpful.- The mapping lives in two mirrored pure functions in the HTTP adapter:
statusFor(err) intandproblemFor(err) (typeURI, title). Every sentinel one recognises has a case in the other, so no error can get a correct status with a generic type. Both useerrors.Is, so wrapped errors keep their mapping. - Malformed JSON is a client error. A dedicated
errMalformedBodysentinel wraps decode failures so they map to400, not to thedefault500. - The mapping stays in the adapter. The domain returns typed sentinels and knows nothing about HTTP — which is why the Kafka inbound adapter can handle the same errors completely differently.
- The spec documents it.
apis/openapi.yamldefines one reusableProblemcomponent referenced by every error response, and is Spectral-linted in CI.
The full catalogue is on the Error model page.
Consequences
Easier
- Clients can branch on a stable identifier.
wip-limit-reached(retry with backoff) andwork-unit-already-completed(stop) are now distinguishable without reading prose, despite sharing409. - Error messages can be reworded freely. Only
detailchanges; no client breaks. - The catalogue is exhaustive and reviewable.
problemForis a single switch listing every error the service can produce — twenty-one categories traceable to a specific sentinel, plus theinternal-errorfallback. 500means something again. Every domain error is mapped explicitly, so an unmapped error reaching thedefaultbranch genuinely indicates infrastructure failure rather than an unhandled business case.- Consistency across the platform. All five services return the same shape.
Harder
- Two places to update per new error. A new sentinel needs a case in
statusForand inproblemFor. Forgetting the second yields a correct status with a genericinternal-errortype — silently wrong. The mirrored structure and a doc comment make it visible, but nothing enforces it. - Type URIs are now a public contract. Renaming
wip-limit-reachedis a breaking change for clients, even though it looks like a string literal. Content-Type: application/problem+jsonsurprises naive clients. Some HTTP libraries only auto-decodeapplication/json. Correct per the RFC, and occasionally an integration snag.- A non-resolving
typeURI invites bug reports. Someone will paste it into a browser and get nothing. Documented in the spec, the README and the error page — and still likely to be asked about. - The migration was a breaking change. Every existing client and every error-path test had to change at once. Done deliberately in one pass rather than by content-negotiating two shapes, which would have doubled the surface permanently to smooth a one-time cost.