Why a bare 500 error turns you into your client's night shift
RFC 9457, the 2023 successor to RFC 7807, defines machine-readable error fields so a client's operators can handle many incidents themselves.
In brief
- RFC 9457 has replaced RFC 7807 and is the current standard for error responses in application/problem+json.
- Machines classify errors by type, people read detail, and operations teams use instance to search logs. Don't make clients parse detail.
- Add extension fields such as runbook or retryable so clients can handle errors themselves, and keep stack dumps out of responses.
It is midnight in the first week after you handed an integration over to a client, and the dashboard of their operations team has turned red. The log holds a single line, 500 Internal Server Error, with the body {"error": "Something went wrong"}.
The client’s on-call engineer cannot tell whose side the fault is on, whether to retry, or where to look in the logs. The only thing they can do is open a ticket and send it to you, and you start the next morning on an incident with no leads.
The standard designed to prevent that scene is RFC 9457, “Problem Details for HTTP APIs”, published in July 2023 at rfc-editor.org.
It defines a JSON object called a “problem detail” that carries error information in machine-readable form, sent under the media type application/problem+json. RFC 9457 replaces RFC 7807, and Apidog calls it the standard answer whenever the question is what an error body should look like.
For an FDE, then, error responses are part of the handover. Design them well and the client resolves many incidents alone; design them badly and you become the permanent on-call engineer for someone else’s system.
What does RFC 9457 answer that a status code does not?
A 422 tells you the request had a problem. It does not say what the problem was, which account it affected, or what the recipient should do next. The fields of RFC 9457 fill that gap.
You may already know RFC 7807. When you write documentation or talk to the client’s architects, cite RFC 9457, because the new document has formally replaced the old one.
The strength of the standard is that each field serves a different reader. type is a URI identifying the problem type, title is a short human-readable summary, detail explains this specific occurrence, and instance identifies that occurrence itself. The table below maps them to the questions an on-call engineer tends to ask:
| Field | Who reads it | Question it answers |
|---|---|---|
type |
The client’s machines | What kind of error is this, so it can be handled automatically? |
title |
People | What is this kind of error, in brief? |
detail |
People | What exactly happened this time? |
instance |
Operations team | What ID does this occurrence carry, for searching the logs? |
| Extension fields | Both | Which account is affected, which guide should I read? |
Example: an API that pushes orders to a warehouse
Say you are integrating a retail chain’s ordering system with your company’s warehouse API. One account has used up its daily order quota. The poor version returns this:
{ "error": "Bad request", "code": 4021 }
The on-call engineer has no idea what 4021 means, so they open another ticket. Here is the RFC 9457 version:
{
"type": "https://docs.example.vn/problems/daily-order-quota-exceeded",
"title": "Daily order quota exceeded",
"detail": "Account ACC-0192 has used up today's order quota. The quota resets at 00:00.",
"instance": "/incidents/7f3a2c",
"account_id": "ACC-0192",
"runbook": "https://docs.example.vn/runbook/order-quota",
"retryable": false
}
Reading this, the on-call engineer knows at once that the fault is on their side and when it will clear by itself. They have a link to the guide for handling it, and if they still need to call you, they have the ID 7f3a2c so you can find the right log line.
account_id, runbook and retryable are extension fields. RFC 9457 lets the definition of each problem type add its own members, so you can attach exactly the information the client’s operations team needs.
The page that type points to is also your error documentation. Postman advises that error documentation list the possible error codes, the common messages and suggested fixes: the three things an on-call engineer needs at midnight. Database table names or Java class names do nothing for them.
Letting the client’s machines handle errors too
The on-call engineer is only half the audience. The other half is the client code that calls your API, and that code needs to know what to branch on.
Given how RFC 9457 divides the roles of its fields, the answer is fairly clear: branch on type, because it identifies the kind of error. detail is written for people and tied to each occurrence, so next week you may change the wording or add figures; any code that reads that string with a regex will break silently.
The illustrative code below shows how the client side should handle the responses in the warehouse example:
PROBLEMS = "https://docs.example.vn/problems/"
def handle_error(resp, method, idempotency_key=None):
if not resp.headers.get("Content-Type", "").startswith("application/problem+json"):
return open_ticket(None)
problem = resp.json()
if problem.get("type") == PROBLEMS + "daily-order-quota-exceeded":
return wait_until_tomorrow(problem.get("account_id"))
safe = method != "POST" or idempotency_key is not None
if problem.get("retryable") is True and safe:
return retry_later(resp.headers.get("Retry-After"), idempotency_key)
return open_ticket(problem.get("instance"))
No line in the function reads detail. However often you reword it, the function still behaves correctly; and when it has to open a ticket, it attaches instance so both sides can find the same incident.
In systems with many services, Apidog recommends also propagating the W3C traceparent header along with a request ID, so the identifier follows the request through every service. Pair instance with that trace and you can follow a client’s ticket back to the exact service that failed.
When to retry, and when to stop?
The retryable flag answers the question every client asks. It is not in the RFC: it is an extension field you define, so you must spell out its meaning on the page that type points to.
An article on Hackernoon advises retrying only on a specific list of error codes, and retrying 429 only when the back-off logic respects the Retry-After header. Apidog is blunter: returning 429 without Retry-After teaches clients to hammer you. Also according to Apidog, almost every other 4xx code is a terminal error that retrying will not fix.
The Hackernoon article also advises that retries should usually skip POST to avoid creating duplicate records. In the warehouse example, if the client’s code resends an order-creating POST after a timeout, the warehouse may receive two identical orders, because a timeout does not reveal whether the first order was recorded.
If the client genuinely needs to retry POST, you can design an idempotency key: the client generates one key per order and resends that same key on every attempt, and when the server sees a key it has already processed, it returns the original result. The header name below is a convention you agree with the client and record in the API documentation:
import uuid
import requests
def create_order(session, order):
key = str(uuid.uuid4()) # generate once per order, never regenerate on retry
headers = {"Idempotency-Key": key}
for _ in range(3):
try:
return session.post(ORDERS_URL, json=order, headers=headers, timeout=10)
except requests.Timeout:
continue # resend the same key; the server will not create a second order
return open_ticket(None)
On the server, store the key with the result of the first processing and return exactly that result when the key appears again. Until this mechanism exists, retryable should be false for every error on the order-creating POST.
An afternoon’s work with Spring
If the API is written in Java/Spring, most of the work is already done. Spring Framework supports RFC 9457 through ProblemDetail and ErrorResponse, enabled by extending ResponseEntityExceptionHandler and declaring it as a @ControllerAdvice. In Spring Boot, one property auto-configures that handler for the built-in exceptions:
spring.mvc.problemdetails.enabled=true
For your own business errors, build a ProblemDetail in an exception handler. Extension fields go through the properties map, and Spring renders them as top-level JSON properties:
@ExceptionHandler(QuotaExceededException.class)
ProblemDetail handleQuota(QuotaExceededException ex) {
ProblemDetail pd = ProblemDetail.forStatusAndDetail(
HttpStatus.UNPROCESSABLE_ENTITY, ex.getMessage());
pd.setType(URI.create("https://docs.example.vn/problems/daily-order-quota-exceeded"));
pd.setTitle("Daily order quota exceeded");
pd.setProperty("account_id", ex.getAccountId());
pd.setProperty("runbook", "https://docs.example.vn/runbook/order-quota");
pd.setProperty("retryable", false);
return pd;
}
The hard part is not the code. It is sitting down with the client’s operations team, listing the errors they actually hit, naming a type for each and writing a runbook for every one. That work resembles customer discovery more than programming.
The common traps
The most dangerous trap is leaking implementation details. RFC 9457 warns against letting things such as stack dumps out over HTTP, and Apidog notes that verbose error bodies are a favorite reconnaissance channel for attackers. Write the stack trace to internal logs keyed to instance; the response to the client carries only that ID.
The second trap is a different error format on every endpoint: error in one place, message in another, HTML somewhere else. Postman advises a consistent error structure across all requests, because a single exception forces the client code to add a special branch.
The third trap is a type that points to an empty URI. An on-call engineer at midnight will click that link, and if it lands on a 404, you have lost the chance for them to fix the problem themselves.
Three common questions when adopting RFC 9457
Can the status field in the body replace the HTTP status code? No. Under RFC 9457, status, if present, is advisory only; the real status code stays in the response’s status line. Keep the two values in sync, but clients should trust the status line.
If a request is wrong in several places, which error do you return? The RFC recommends returning the most relevant or most urgent problem. For an operations team, that is the error blocking them from moving on, not the first one the validator happened to hit.
If you already use RFC 7807, do you need to change anything? RFC 9457 has replaced RFC 7807, so the minimum is to update documentation and technical discussions to cite the new document.
How to tell this story in an FDE interview
A question like “what did you do to reduce tickets after handover?” is a good opening for this skill. A generic answer such as “careful error handling” will not convince anyone; describe the exact sequence of work and the numbers that came with it.
Take a hypothetical case built on the warehouse API above. Before standardizing, your team receives about 25 tickets a week from the client, mostly quota errors and bad order data.
Once every error returns application/problem+json, each type has a runbook and the client’s code branches on type, the tickets reaching you fall to about 6, because the client closes the quota and data errors themselves.
The interview answer then has three beats: the problem (tickets with no log ID), what you did (RFC 9457, a runbook for each type, idempotency keys for POST), and the measured result.
On a CV, a line such as “standardized error responses on RFC 9457, cutting post-handover tickets from X to Y a week” is only worth something when X and Y are numbers you actually measured, so start counting tickets from the first week of the engagement.
The next time a midnight error is resolved on the client’s side without anyone calling you, that is the sign the error responses were designed properly.
Was this article useful?
Thanks for the feedback!