# `DocRaptor.Error`
[🔗](https://github.com/ruskenberry/docraptor/blob/v0.1.2/lib/doc_raptor/error.ex#L1)

Structured error from client validation or the DocRaptor API.

All public APIs return `{:error, %DocRaptor.Error{}}` on failure (no bang
functions). This is **not** an exception: there is no `defexception`, so do
not `raise` it and do not call `Exception.message/1` on it — pattern-match
the struct (see [Usage](usage.html)).

| Reason | When |
| --- | --- |
| `:missing_api_key` | `Client.new/1` without a non-empty `:api_key` |
| `:invalid_document` | Local encode failed (`name` / type / content xor url) |
| `:api` | Non-2xx HTTP or unexpected DocRaptor JSON |
| `:transport` | Req/network failure before a usable HTTP response |
| `:timeout` | `DocRaptor.await_async_doc/3` exceeded `:timeout_ms` |
| `:async_failed` | Async status reported `failed` |

Fields:

- `:reason` — tagged atom above
- `:message` — human-readable summary (for `:api`, often extracted from XML `<error>` tags)
- `:status` — HTTP status when available
- `:body` — raw response body (often binary), transport reason, or `%Status{}`

# `reason`

```elixir
@type reason() ::
  :missing_api_key
  | :invalid_document
  | :api
  | :transport
  | :timeout
  | :async_failed
  | atom()
```

# `t`

```elixir
@type t() :: %DocRaptor.Error{
  body: term(),
  message: String.t(),
  reason: reason(),
  status: pos_integer() | nil
}
```

---

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