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

Structured error type for all TruelayerClient operations.

Every public API function returns `{:ok, result}` or `{:error, %TruelayerClient.Error{}}`.

## Fields

  * `:type` - machine-readable error category atom
  * `:status` - HTTP status code (nil for non-HTTP errors)
  * `:trace_id` - `Tl-Trace-Id` header value for support
  * `:should_retry` - whether TrueLayer indicated `Tl-Should-Retry: true`
  * `:title` - RFC 7807 error title
  * `:detail` - RFC 7807 error detail
  * `:errors` - per-field validation errors (400 responses)
  * `:reason` - underlying reason for non-API errors

## Examples

    case TruelayerClient.Payments.get_payment(client, id) do
      {:ok, payment} -> payment
      {:error, %TruelayerClient.Error{type: :not_found}} -> nil
      {:error, %TruelayerClient.Error{trace_id: tid} = err} ->
        Logger.error("TrueLayer error trace=#{tid}: #{Exception.message(err)}")
    end

# `error_type`

```elixir
@type error_type() ::
  :api_error
  | :auth_error
  | :validation_error
  | :not_found
  | :unauthorized
  | :forbidden
  | :conflict
  | :rate_limited
  | :server_error
  | :signing_required
  | :replay_attack
  | :signature_invalid
  | :network_error
  | :decode_error
  | :timeout
  | :unknown
```

# `t`

```elixir
@type t() :: %TruelayerClient.Error{
  __exception__: true,
  detail: String.t() | nil,
  errors: [map()] | nil,
  reason: term(),
  should_retry: boolean(),
  status: non_neg_integer() | nil,
  title: String.t() | nil,
  trace_id: String.t() | nil,
  type: error_type()
}
```

# `conflict?`

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

Returns `true` for 409 Conflict errors.

# `from_response`

```elixir
@spec from_response(map(), map(), non_neg_integer()) :: t()
```

Build an `Error` from an API response.

# `network`

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

Build a network/transport error.

# `not_found?`

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

Returns `true` for 404 Not Found errors.

# `rate_limited?`

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

Returns `true` for 429 Rate Limited errors.

# `retryable?`

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

Returns `true` when the error is safe to retry.

# `server_error?`

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

Returns `true` for 5xx Server errors.

# `signing_required`

```elixir
@spec signing_required() :: t()
```

Build a signing-not-configured error.

# `unauthorized?`

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

Returns `true` for 401 Unauthorized errors.

---

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