Skip to content

Commit 75d42a2

Browse files
committed
docs: Document error response format (RFC 7807) in README
Add an "Error responses" subsection covering: - The application/problem+json body shape (type, title, status, detail, pointer, keyword) emitted by ProblemDetailRenderer. - Single-error reporting (first failure wins). - JSON-Pointer pointer field per RFC 6901. - Common keyword values for validation failures. - An example body for a typical coercion failure. - 404 / 405 / 500 surfaces and how to override via ExceptionHandler.
1 parent 7fc5b19 commit 75d42a2

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,42 @@ Form-field coercion mirrors the rules already used at the parameter boundary: th
114114

115115
Both built-in parsers honour the `charset=` parameter on the `Content-Type` header (default UTF-8). Unknown charsets fall back to UTF-8.
116116

117+
### Error responses (RFC 7807)
118+
119+
Validation failures — missing required fields, type mismatches, unsupported content types, coercion errors, malformed bodies — produce an `HTTP 400 Bad Request` response with body media type `application/problem+json`, following [RFC 7807](https://datatracker.ietf.org/doc/html/rfc7807).
120+
121+
A single error is reported per request (first failure wins). The response body has these fields:
122+
123+
| Field | Type | Description |
124+
| ---------- | ------- | ---------------------------------------------------------------------------------------- |
125+
| `type` | string | Always `about:blank` (no per-error type URI). |
126+
| `title` | string | Always `Bad Request`. |
127+
| `status` | integer | Always `400`. |
128+
| `detail` | string | Human-readable description of the failure (e.g. `expected integer`). |
129+
| `pointer` | string | [RFC 6901](https://datatracker.ietf.org/doc/html/rfc6901) JSON-Pointer to the failing location (e.g. `/body/age`, `/query/limit`, `/path/id`, or `/body` for body-wide errors). |
130+
| `keyword` | string | The validation rule that failed: `type`, `required`, `enum`, `pattern`, `format`, `minimum`, `maximum`, `minLength`, `maxLength`, `additionalProperties`, `oneOf`, `anyOf`, `allOf`, `not`, `const`, `content-type`, `decode`, … |
131+
132+
Example body for `POST /form-echo` with `age=abc` (`age` is declared as `integer`):
133+
134+
``` json
135+
{
136+
"type": "about:blank",
137+
"title": "Bad Request",
138+
"status": 400,
139+
"detail": "expected integer",
140+
"pointer": "/age",
141+
"keyword": "type"
142+
}
143+
```
144+
145+
Other error responses:
146+
147+
- **404 Not Found** — no route matches the request path (no body).
148+
- **405 Method Not Allowed** — path matches but the HTTP method isn't declared. Includes an `Allow` header listing permitted methods (no body).
149+
- **500 Internal Server Error** — uncaught exception from a handler. No body by default; override `ExceptionHandler` if you need a different envelope.
150+
151+
The error mapping is performed by `Handlers.defaultExceptionHandler()`. Pass your own `ExceptionHandler` to `OpenApiServer.builder().exceptionHandler(...)` if you need a different response shape (e.g. multi-error collection, custom problem types, locale-aware `detail`).
152+
117153
### Extra (non-OpenAPI) handlers
118154

119155
Mount handlers at arbitrary paths outside the OpenAPI spec — useful for liveness probes,

0 commit comments

Comments
 (0)