# `LightningWeb.API.Problem`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning_web/api/problem.ex#L1)

An RFC 9457 problem document, and the one function that sends one.

Every problem response is built with `new/2` from a response code in
`LightningWeb.API.Codes` and sent with `respond/2` or `halt/2`, whoever
answers: `LightningWeb.API.FallbackController`, a plug, a webhook, or
`LightningWeb.Endpoint` after an exception.

# `t`

```elixir
@type t() :: %LightningWeb.API.Problem{
  code: LightningWeb.API.Codes.code(),
  errors: [LightningWeb.API.Errors.entry()],
  extensions: map(),
  headers: [{String.t(), String.t()}],
  status: pos_integer()
}
```

# `body`

```elixir
@spec body(t()) :: map()
```

The problem document `respond/2` sends.

# `content_type`

```elixir
@spec content_type(Plug.Conn.t()) :: String.t()
```

The content type a problem sent on `conn` takes: `application/problem+json`
when the request's `Accept` names it, in any position and whatever its `q`,
and `application/json` otherwise.

# `halt`

```elixir
@spec halt(Plug.Conn.t(), t()) :: Plug.Conn.t()
```

Sends `problem` as the response, as `respond/2` does, and halts the plug
pipeline.

# `new`

```elixir
@spec new(LightningWeb.API.Codes.code(), keyword()) :: t()
```

Builds the problem for a response code from `LightningWeb.API.Codes`.

Options:

  * `:errors` - the entries, from `LightningWeb.API.Errors`.
  * `:extensions` - extra top-level members for this answer, such as
    `work_order_id`.
  * `:headers` - response headers that belong to the answer.
  * `:retry_after` - seconds, sent as `retry-after`; `nil` sends none.
  * `:status` - one of `LightningWeb.API.Codes.statuses/1` for `code`
    other than its own, for a route that keeps a status of its own, such
    as 429 for every limiter refusal on `/i/*`.

# `respond`

```elixir
@spec respond(Plug.Conn.t(), t()) :: Plug.Conn.t()
```

Sends `problem` as the response.

The body is the same whatever the request's `Accept`. The content type is
`application/problem+json` only when `Accept` names it, and
`application/json` otherwise.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
