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

Structured error types returned by all Codat API functions.

All API functions return `{:ok, result}` or `{:error, %Codat.Error{}}`.

## Error Types

| Type                   | HTTP Status | Description                                 |
|------------------------|-------------|---------------------------------------------|
| `:unauthorized`        | 401         | Invalid or missing API key                  |
| `:payment_required`    | 402         | Free tier limit exceeded                    |
| `:forbidden`           | 403         | Insufficient permissions                    |
| `:not_found`           | 404         | Resource or data type not found             |
| `:conflict`            | 409         | Data not yet ready or resource conflict     |
| `:rate_limited`        | 429         | Too many requests                           |
| `:bad_request`         | 400         | Invalid request body or parameters          |
| `:server_error`        | 5xx         | Codat internal server error                 |
| `:service_unavailable` | 503         | Service temporarily unavailable             |
| `:network_error`       | N/A         | TCP/TLS/connection failure                  |
| `:timeout`             | N/A         | Request timed out                           |
| `:json_decode_error`   | N/A         | Unexpected response body                    |

# `error_type`

```elixir
@type error_type() ::
  :unauthorized
  | :payment_required
  | :forbidden
  | :not_found
  | :conflict
  | :rate_limited
  | :bad_request
  | :unprocessable
  | :server_error
  | :service_unavailable
  | :network_error
  | :timeout
  | :json_decode_error
  | :unknown
```

# `t`

```elixir
@type t() :: %Codat.Error{
  correlation_id: String.t() | nil,
  detail: map() | nil,
  message: String.t() | nil,
  raw_body: String.t() | nil,
  retry_after: non_neg_integer() | nil,
  status_code: non_neg_integer() | nil,
  type: error_type()
}
```

# `from_exception`

```elixir
@spec from_exception(Exception.t()) :: t()
```

Builds a `%Codat.Error{}` from a network/transport-level error.

# `from_response`

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

Builds a `%Codat.Error{}` from an HTTP response map.

# `message`

```elixir
@spec message(t()) :: String.t()
```

Human-readable string representation of the error.

# `retryable?`

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

Returns true if the error is considered retryable (transient).

---

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