# `Wise.Error`
[🔗](https://github.com/iamkanishka/wise/blob/v1.0.0/lib/wise/error.ex#L1)

Structured error returned from the Wise Platform API.

All API errors are returned as `{:error, %Wise.Error{}}` tuples.
Network errors are returned as `{:error, %Wise.Error{type: :network}}`.

## Fields

  - `type` - `:api`, `:network`, `:circuit_open`, `:invalid_signature`, `:rate_limited`
  - `status_code` - HTTP status code (nil for network errors)
  - `code` - Wise machine-readable error code e.g. `"SCA_REQUIRED"`
  - `message` - Human-readable description
  - `errors` - Per-field validation errors (populated on 422)
  - `request_id` - X-Request-Id header value for Wise support

## Example

    case Wise.Transfers.fund(client, profile_id, transfer_id) do
      {:ok, result} -> result
      {:error, %Wise.Error{code: "SCA_REQUIRED"}} -> redirect_to_sca()
      {:error, %Wise.Error{status_code: 429}} -> handle_rate_limit()
      {:error, %Wise.Error{type: :network}} -> handle_network_error()
    end

# `error_type`

```elixir
@type error_type() ::
  :api | :network | :circuit_open | :invalid_signature | :rate_limited
```

# `field_error`

```elixir
@type field_error() :: %{field: String.t(), code: String.t(), message: String.t()}
```

# `t`

```elixir
@type t() :: %Wise.Error{
  __exception__: true,
  code: String.t() | nil,
  errors: [field_error()],
  message: String.t() | nil,
  request_id: String.t() | nil,
  status_code: non_neg_integer() | nil,
  type: error_type()
}
```

# `circuit_open?`

```elixir
@spec circuit_open?(t()) :: boolean()
```

Returns true if the circuit breaker rejected the request.

# `field_errors`

```elixir
@spec field_errors(t()) :: [field_error()]
```

Extracts per-field validation errors from a 422 response.

# `network_error?`

```elixir
@spec network_error?(t()) :: boolean()
```

Returns true if this is a network-level error.

# `not_found?`

```elixir
@spec not_found?(t()) :: boolean()
```

Returns true if this is a 404 Not Found error.

# `rate_limited?`

```elixir
@spec rate_limited?(t()) :: boolean()
```

Returns true if this is a 429 rate limit error.

# `sca_required?`

```elixir
@spec sca_required?(t()) :: boolean()
```

Returns true if SCA (Strong Customer Authentication) is required.

# `server_error?`

```elixir
@spec server_error?(t()) :: boolean()
```

Returns true if this is a 5xx server error.

# `unauthorized?`

```elixir
@spec unauthorized?(t()) :: boolean()
```

Returns true if this is a 401 Unauthorized error.

---

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