Inconsistent error payloads frustrate API developers and increase client-side error handling boilerplate. Standardizing error structures using RFC 7807 (Problem Details for HTTP APIs) ensures every error response is machine-parsable and self-describing.
1. Core RFC 7807 Attributes
RFC 7807 establishes five standard top-level JSON fields for all API error responses:
- type (string - URI): A absolute URI reference identifying the specific error condition type.
- title (string): A short, human-readable summary of the problem type (should not change between occurrences of the error).
- status (integer): The HTTP status code generated by the origin server (matches response header).
- detail (string): A human-readable explanation specific to this occurrence of the problem.
- instance (string - URI): A relative or absolute URI reference identifying the specific request attempt (e.g. request ID or log trace path).
2. Production RFC 7807 Response Example
{
"type": "https://api.example.com/errors/invalid-credit-card",
"title": "Credit Card Charging Failed",
"status": 422,
"detail": "The expiration date provided (08/2024) is in the past.",
"instance": "/v1/charges/req_92837410293",
"invalidParams": [
{
"name": "expMonth",
"reason": "Month must be equal to or greater than current calendar month."
}
]
}Validate Your Error Response Schemas
Check if your OpenAPI specification declares explicit error status codes (400, 401, 403, 404, 500) and adheres to RFC 7807 schemas.
