---
title: "Structured Error Messages for HTTP APIs - API7.ai"
description: "Ever since I started to work on the Apache APISIX project, I've been trying to improve my knowledge and understanding of HTTP APIs."
url: "https://api7.ai/blog/structured-errors-http-apis"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Technology

# Structured Error Messages for HTTP APIs

[![Nicolas Fränkel](https://avatars.githubusercontent.com/u/752258?v=4)](https://github.com/nfrankel)

[Nicolas Fränkel](https://github.com/nfrankel)

November 2, 2022

[Technology](https://api7.ai/category/technology)

Ever since I started to work on the [Apache APISIX](https://apisix.apache.org/) project, I've been trying to improve my knowledge and understanding of ~~REST~~ ~~RESTful~~ HTTP APIs. For this, I'm reading and watching the following sources:

- Books. At the moment, I'm finishing [API Design Patterns](https://www.manning.com/books/api-design-patterns). Expect a review soon.
- YouTube. I'd recommend [ErikWilde' channel](https://www.youtube.com/ErikWilde). While some videos are better than others, they all focus on APIs.
- IETF RFCs. Most RFCs are not about APIs, but a friendly person compiled a list of the [ones who are](https://standards.rest/).

Today, I'd like to introduce the "Problem Details for HTTP APIs" RFC, *aka*, [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807).

## The problem(s)

HTTP APIs communicate the requested action through [HTTP method semantics](https://api7.ai/learning-center/api-101/http-methods-in-apis) and the outcome through a status code. For errors, HTTP defines two ranges: client errors, `4xx`, and server errors, `5xx`.

Imagine a banking API that allows you to make transfers. It should fail if you try to transfer more funds to your account. A couple of HTTP status codes can fit:

- `400 Bad Request`: The server cannot or will not process the request due to something that is perceived to be a client error
- `402 Payment Required`: The request cannot be processed until the client makes a payment. However, no standard use convention exists, and different entities use it in other contexts.
- `409 Conflict`: The request conflict with the current state of the target resource

Here's the first problem: HTTP status codes were specified for human-to-machine interactions via browsers, not for machine-to-machine interactions via APIs. Hence, selecting a status code that maps one-to-one to the use case is rarely straightforward. For the record, [Martin Fowler seems to favor 409 in our case](https://martinfowler.com/articles/richardsonMaturityModel.html).

Whatever the status code, the second problem concerns the error payload or, more precisely, its structure. The structure is unimportant if a single organization manages the client and the API provider. Even if a dedicated team develops each of them, they can align. For example, imagine a mobile app that calls its own API.

However, issues arise when a team decides to use a third-party API. The choice of the response structure is significant in this case because it's now considered part of a contract: any change from the provider may break the clients. Worse, the structure is likely different from provider to provider.

Hence, a standardized error reporting structure:

- Provides uniformity across providers
- Increases API stability

## RFC 7807

[RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) aims to solve the problem by providing a standardized error structure.

The structure is the following:

![Structure](https://blog.frankel.ch/assets/generated/structured-errors-http-apis/problemdetails.svg)

The RFC describes the fields:

> - `"type"` (`string`) - A URI reference [\[RFC3986\]](https://www.rfc-editor.org/rfc/rfc3986) that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (*e.g.*, using HTML [\[W3C.REC-html5-20141028\]](https://www.rfc-editor.org/rfc/rfc7807#ref-W3C.REC-html5-20141028)). When this member is not present, its value is assumed to be `"about:blank"`.
> - `"title"` (`string`) - A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization (*e.g.*, using proactive content negotiation; see [\[RFC7231, Section 3.4\]](https://www.rfc-editor.org/rfc/rfc7231#section-3.4)).
> - `"status"` (`number`) - The ([\[RFC7231\], Section 6](https://www.rfc-editor.org/rfc/rfc7231#section-6)) generated by the origin server for this occurrence of the problem.
> - `"detail"` (`string`) - A human-readable explanation specific to this occurrence of the problem.
> - `"instance"` (`string`) - A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
>
> \-- [Members of a Problem Details Object](https://www.rfc-editor.org/rfc/rfc7807#section-3.1)

The RFC offers the following sample when there needs to be more funds to make a banking transfer.

![RFC Example](https://static.api7.ai/uploads/2026/01/30/JbundvX6_problemdetails-json-sample.png?imageMogr2/format/webp)

## An example

I'll use one of my [existing demo](https://github.com/nfrankel/evolve-apis/) as an example. The demo highlights several steps to ease the process of evolving your APIs.

In step 6, I want users to register, so I limit the number of calls in a time window if they aren't authenticated. I've created a dedicated Apache APISIX plugin for this. After the number of calls has reached the limit, it returns:

```
HTTP/1.1 429 Too Many Requests
Date: Fri, 28 Oct 2022 11:56:11 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.15.0

{"error_msg":"Please register at https:\/\/apisix.org\/register to get your API token and enjoy unlimited calls"}
```

Let's structure the message as per RFC 7807.

![RFC 7807 Rules](https://static.api7.ai/2022/11/03/problemdetails-json-register.svg)

## Conclusion

RFC 7807 not only helps client developers. It's a tremendous help for API implementors as it provides quick guidelines to avoid reinventing the wheel on every project.

**Go further:**

- [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807)
- [Standards.REST](https://standards.rest/)
- [HTTP Client Error 4xx](https://httpwg.org/specs/rfc9110.html#status.4xx)

*Originally published at [A Java Geek](https://blog.frankel.ch/structured-errors-http-apis/) on October 30th, 2022*

Tags:

[Codec](https://api7.ai/tags/codec)

Share article link

Share

Related Posts

[![NGINX HTTP/2 RCE: Patch the Gateway, Then Verify the Path](https://static.api7.ai/uploads/2026/11/24/sTZr9vkE_nginx-http2-gateway-patching.webp)](https://api7.ai/blog/nginx-http2-gateway-patching)

## [NGINX HTTP/2 RCE: Patch the Gateway, Then Verify the Path](https://api7.ai/blog/nginx-http2-gateway-patching)

[![Retry LLM Streams Without Duplicate Output](https://static.api7.ai/uploads/2026/11/24/qZaFW9BE_llm-streaming-retry-failover.webp)](https://api7.ai/blog/llm-streaming-retry-failover)

## [Retry LLM Streams Without Duplicate Output](https://api7.ai/blog/llm-streaming-retry-failover)

Table of Contents

- [The problem(s)](#the-problems)
- [RFC 7807](#rfc-7807)
- [An example](#an-example)
- [Conclusion](#conclusion)

## Related Posts

[![A Coredump Story About NGINX ctx and error\_page](https://static.api7.ai/2022/12/04/638c8054cf09c.png)](https://api7.ai/blog/coredump-debug-story-about-nginx)

Technology

September 16, 2022

#### [A Coredump Story About NGINX ctx and error\_page](https://api7.ai/blog/coredump-debug-story-about-nginx)

Recently, we helped an APISIX user debug a strange coredump error. We would like to share some interesting points, providing guidance for debugging NGINX and APISIX.

[Codec](https://api7.ai/tags/codec)

[NGINX](https://api7.ai/tags/nginx)

[Comparison to Competitors](https://api7.ai/tags/comparison-to-competitors)

[![How to Avoid Catastrophic Backtracking in Regex?](https://static.api7.ai/2022/11/18/637727bba2b55.png)](https://api7.ai/blog/how-to-avoid-catastrophic-backtracking-completely)

Technology

December 17, 2020

#### [How to Avoid Catastrophic Backtracking in Regex?](https://api7.ai/blog/how-to-avoid-catastrophic-backtracking-completely)

Catastrophic Backtracking of regular expressions refers to the fact that the regular ...

[Regex](https://api7.ai/tags/regex)

[Codec](https://api7.ai/tags/codec)

[![API Gateway Multi-Tenancy: Routes Beat a Server per Endpoint](https://static.api7.ai/uploads/2026/11/24/GTCWjh37_api-gateway-multitenancy-routing.webp)](https://api7.ai/blog/api-gateway-multitenancy-routing)

Technology

November 24, 2026

#### [API Gateway Multi-Tenancy: Routes Beat a Server per Endpoint](https://api7.ai/blog/api-gateway-multitenancy-routing)

Design shared API ingress by separating listeners, hostnames, routes, policies, and upstreams instead of treating every endpoint as another server process.

[API Gateway](https://api7.ai/tags/api-gateway)

[Multi-Tenancy](https://api7.ai/tags/multi-tenancy)

[API Routing](https://api7.ai/tags/api-routing)
