# `Infusion.Runtime.Error`
[🔗](https://github.com/mandar1045/infusion/blob/v0.1.0/runtime/lib/infusion/runtime/error.ex#L1)

The error every SDK call returns as `{:error, %Infusion.Runtime.Error{}}`.

`type` tells what went wrong, so callers can match on it instead of on
status codes:

| type | when |
|---|---|
| `:bad_request` | 400 |
| `:authentication` | 401 |
| `:permission_denied` | 403 |
| `:not_found` | 404 |
| `:conflict` | 409 |
| `:unprocessable_entity` | 422 |
| `:rate_limit` | 429, or any status with `x-ratelimit-remaining: 0` (GitHub sends 403) |
| `:internal_server` | 500 and above |
| `:api_error` | any other status of 400 and above, or an error event in a stream |
| `:timeout` | no response in time |
| `:connection` | the request could not be sent or the connection broke |

For status errors, `body` is the decoded response body, `headers` the
response headers and `request_id` the API's request ID, if it sent one
(quote it when contacting the vendor's support). For `:timeout` and
`:connection`, `reason` holds the underlying error.

# `t`

```elixir
@type t() :: %Infusion.Runtime.Error{
  __exception__: term(),
  body: term(),
  headers: %{optional(String.t()) =&gt; [String.t()]},
  message: String.t(),
  reason: term(),
  request_id: String.t() | nil,
  status: non_neg_integer() | nil,
  type: type()
}
```

# `type`

```elixir
@type type() ::
  :bad_request
  | :authentication
  | :permission_denied
  | :not_found
  | :conflict
  | :unprocessable_entity
  | :rate_limit
  | :internal_server
  | :api_error
  | :timeout
  | :connection
```

---

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