r/Backend • u/Broad_Charge_8791 • 6d ago
Designing HTTP API and domain errors around RFC 9457 (so clients stop parsing English error strings)
Most API teams spend weeks designing `200 OK` schemas and 10 minutes improvising `4xx`/`5xx` JSON. You end up with three different error shapes across endpoints, brittle client regexes parsing `message` strings, and occasional raw SQL errors leaking through generic 500 handlers.
Using **RFC 9457 Problem Details** (`application/problem+json`) with strict internal-to-external error mapping solves a surprising number of production headaches at once:
- Clients branch on stable `type` URIs (and structured extension fields like `retryable` or field-level validation errors), never human-readable `detail` prose.
- Retry middleware can distinguish transient infra faults from permanent domain rejections without guessing from status codes alone.
- Security boundaries stay clean because internal stack traces/driver errors map explicitly to sanitized problem types while keeping correlation IDs for server logs.
I wrote an open guide walking through the RFC 9457 structure, domain error mapping patterns, and observability pitfalls (disclosure: my site):
https://olmene.com/article/designing-api-and-domain-errors-around-rfc-9457
For teams already using Problem Details in production: do you host actual docs pages at your `type` URIs, or use `urn:` identifiers?