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

Structured error returned from all Worldpay API calls.

## Fields

- `:type` — error classification atom
- `:status` — HTTP status code (`nil` for non-HTTP errors)
- `:reason` — atom describing the failure
- `:message` — human-readable description
- `:raw` — raw API response body (map or string)
- `:custom_code` — Worldpay `customCode` field
- `:validation_errors` — list of field-level validation errors from the API

# `error_type`

```elixir
@type error_type() ::
  :http_error
  | :api_error
  | :timeout
  | :network_error
  | :circuit_open
  | :decode_error
  | :configuration_error
```

# `t`

```elixir
@type t() :: %Worldpay.Error{
  __exception__: true,
  custom_code: String.t() | nil,
  message: String.t() | nil,
  raw: map() | String.t() | nil,
  reason: atom() | nil,
  status: non_neg_integer() | nil,
  type: error_type() | nil,
  validation_errors: [map()] | nil
}
```

# `from_exception`

```elixir
@spec from_exception(struct() | term()) :: t()
```

Build from a network / transport error.

# `from_response`

```elixir
@spec from_response(pos_integer(), %{required(String.t()) =&gt; term()} | String.t()) ::
  t()
```

Build from a raw Worldpay JSON error body.

---

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