# `Magpie.Error`
[🔗](https://github.com/alexcassol/magpie/blob/v0.3.1/lib/magpie/error.ex#L1)

Normalized Dropbox API error.

Every Magpie function returns `{:error, %Magpie.Error{}}` when Dropbox
answers with a non-success status:

  * `status` — the HTTP status code (e.g. `409`)
  * `summary` — Dropbox's `error_summary` string when present
    (e.g. `"path/not_found/.."`), `nil` otherwise
  * `body` — the full decoded error payload

It is also an exception, so it can be raised — `Magpie.Pager` streams do
exactly that, since a `Stream` cannot return an error tuple
mid-enumeration:

    case Magpie.Files.create_folder(client, "/Existing") do
      {:ok, %{"metadata" => metadata}} -> metadata
      {:error, %Magpie.Error{status: 409, summary: "path/conflict" <> _}} -> :already_exists
      {:error, error} -> raise error
    end

# `t`

```elixir
@type t() :: %Magpie.Error{
  __exception__: term(),
  body: term(),
  status: pos_integer(),
  summary: String.t() | nil
}
```

# `new`

Builds a `Magpie.Error` from an HTTP status and a decoded response body,
extracting Dropbox's `error_summary` when present.

OAuth 2 errors (`Magpie.Auth`) have no `error_summary` — their `error`
field is a plain string such as `"invalid_grant"`, which is used as the
summary instead.

    iex> Magpie.Error.new(409, %{"error_summary" => "path/conflict/folder/.."}).summary
    "path/conflict/folder/.."

    iex> Magpie.Error.new(400, %{"error" => "invalid_grant"}).summary
    "invalid_grant"

---

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