API Engineering

API Error Handling: RFC 7807 / RFC 9457 Problem Details for HTTP APIs

Implement standardized REST API error formats using IETF RFC 7807 / RFC 9457 Problem Details for HTTP APIs. Prevent client confusion with structured error objects.

By Cometflow API Engineering Team • Updated 2026-10-06

Inconsistent error envelopes ({ "err": "..." } vs. { "errors": [...] }) force frontend teams to write fragile error-parsing conditionals. IETF RFC 7807 (updated by RFC 9457) defines the standard application/problem+json schema for machine-readable HTTP API errors.

1. Standard Problem Details Payload

HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json

{
  "type": "https://api.example.com/errors/validation-failed",
  "title": "Request Validation Failed",
  "status": 422,
  "detail": "One or more fields failed schema validation.",
  "instance": "/v1/invoices/inv_89124a",
  "invalidParams": [
    { "field": "issueDate", "reason": "Must be a valid ISO-8601 date (YYYY-MM-DD)" }
  ]
}

Frequently Asked Questions (FAQ)

Should production APIs ever return stack traces in the detail field?

Never. Exposing internal file paths, SQL queries, or library versions in public error responses leaks implementation details to attackers. Log the stack trace server-side keyed by a unique correlation traceId and return only the correlation ID to the client.