# `Noizu.WhatsApp.Error`
[🔗](https://github.com/noizu-labs-sdks/elixir-whatsapp/blob/v0.1.0/lib/noizu/whatsapp/error.ex#L1)

Structured error returned by every failing call as `{:error, %Noizu.WhatsApp.Error{}}`.

Returned, never raised in the normal flow (it is a `defexception` so
pagination streams can raise it mid-enumeration).

| `:tag` | `:reason` | When |
|---|---|---|
| `:api` | Graph error `code` (integer, e.g. `131047`) | non-2xx with the Graph `error` envelope |
| `:rate_limited` | `:rate_limited` | 429 still returned after the bounded retry gave up |
| `:http` | `:http_error` | non-2xx without a Graph envelope |
| `:transport` | the transport exception | connection refused, timeout, … |
| `:config` | an atom (`:missing_token`, …) | missing token / phone number id / WABA id |
| `:validation` | an atom (e.g. `:invalid_phone`) | client-side validation |

* `:kind` — semantic error class. Graph code `131047` (re-engagement message
  sent outside the 24h customer-service window) maps to `:window_closed`;
  use `send_template/4` to restart the window.
* `:subcode` — the Graph `error_subcode` when present.
* `:body` — the decoded Graph error object.
* `:summary` — the Graph `message` string. Message text never contains a
  full phone number (`Noizu.WhatsApp.Phone.mask/1`) or the access token.

# `kind`

```elixir
@type kind() :: :window_closed | nil
```

# `t`

```elixir
@type t() :: %Noizu.WhatsApp.Error{
  __exception__: term(),
  body: term(),
  code: integer() | nil,
  kind: kind(),
  message: String.t(),
  reason: term(),
  status: pos_integer() | nil,
  subcode: integer() | nil,
  summary: String.t() | nil,
  tag: :api | :rate_limited | :http | :transport | :config | :validation | nil
}
```

# `config`

```elixir
@spec config(atom(), String.t()) :: t()
```

Missing configuration. `subject` is masked via `Phone.mask/1` when numeric.

# `from_response`

```elixir
@spec from_response(pos_integer(), term()) :: t()
```

Builds an error from an HTTP status and decoded response body.

# `kind_for`

```elixir
@spec kind_for(term()) :: kind()
```

Graph error code -> semantic kind.

# `transport`

```elixir
@spec transport(term()) :: t()
```

Wraps a transport-level failure.

# `validation`

```elixir
@spec validation(atom(), String.t()) :: t()
```

Client-side validation failure. Phone-like values are masked.

---

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