# `Pluggy.Error`
[🔗](https://github.com/fellipessanha/pluggy_ai_ex/blob/main/lib/pluggy/error.ex#L1)

Represents an error returned by the Pluggy API or a transport-level failure.

## Fields

  * `:code` - HTTP status code (integer) or `:transport` for connection errors
  * `:message` - Human-readable error message
  * `:code_description` - Optional machine-readable error code from the API
  * `:data` - Optional additional error data from the API

# `t`

```elixir
@type t() :: %Pluggy.Error{
  code: integer() | :transport,
  code_description: String.t() | nil,
  data: map() | nil,
  message: String.t()
}
```

# `from_response`

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

Builds an error from an API response body (already snake_cased by the pipeline).

## Examples

    iex> Pluggy.Error.from_response(%{code: 401, message: "Unauthorized"})
    %Pluggy.Error{code: 401, message: "Unauthorized"}

    iex> Pluggy.Error.from_response(%{code: 400, message: "Bad Request", code_description: "VALIDATION_ERROR", data: %{field: "amount"}})
    %Pluggy.Error{code: 400, message: "Bad Request", code_description: "VALIDATION_ERROR", data: %{field: "amount"}}

# `transport`

```elixir
@spec transport(atom() | String.t()) :: t()
```

Builds an error for transport-level failures (timeout, connection refused, etc.).

## Examples

    iex> Pluggy.Error.transport(:timeout)
    %Pluggy.Error{code: :transport, message: "timeout"}

---

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