# `ProblemDetails`

An HTTP API's error body (RFC 9457): what kind of problem it is (`about:blank` when `none`), the status, a short title, a detail for people and the URL of this occurrence, each of which may be `none`. `type_` is sent as `type`, a reserved word in code.

[Web and network](types.md#web-and-network); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `ProblemDetails { type_: ...  status: ...  title: ... }`.

## Fields

| Field | Type |
|---|---|
| `type_` | [`Url`](type-url.md)`?` |
| `status` | [`HttpStatus`](type-http-status.md)`?` |
| `title` | `Text?` |
| `detail` | `Text?` |
| `instance` | [`Url`](type-url.md)`?` |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its parts.

| JSON |
|---|
| `{"type":"https://example.com/probs/out-of-credit","status":403,"title":"You do not have enough credit.","detail":"You have 30 credits, but that costs 50.","instance":"https://example.net/account/12345/msgs/abc"}` |
| `{"status":404,"title":"Not Found"}` |
| `{"status":503}` |
| `{}` |

It is stored in 5 columns, each named for the field, `_` and its suffix. This is `{"status":503}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_type` | `text` | `NULL::text` |
| `<field>_status` | `smallint` | `503` |
| `<field>_title` | `text` | `NULL::text` |
| `<field>_detail` | `text` | `NULL::text` |
| `<field>_instance` | `text` | `NULL::text` |

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"type":"https://example.com/probs/out-of-credit","status":403,"title":"You do not have enough credit.","detail":"You have 30 credits, but that costs 50.","instance":"https://example.net/account/12345/msgs/abc"}` | `"You do not have enough credit.\nYou have 30 credits, but that costs 50."` |
| `{"status":404,"title":"Not Found"}` | `Not Found` |
| `{"status":503}` | `503` |
| `{}` | `about:blank` |

## Operations

It has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
