Magpie.Error exception (Magpie v0.1.0)

Copy Markdown View Source

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

Summary

Functions

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

Types

t()

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

Functions

new(status, body)

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