Magpie.Error exception (Magpie v0.6.2)

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
  • request_id — Dropbox's request identifier, useful when contacting support

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, %Magpie.FolderMetadata{} = folder} -> folder
  {:error, %Magpie.Error{status: 409, summary: "path/conflict" <> _}} -> :already_exists
  {:error, error} -> raise error
end

Summary

Functions

Returns whether an error represents failed authentication or authorization.

Returns whether Dropbox reported a path, file, or folder conflict.

Returns whether an error represents a content integrity mismatch.

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

Returns whether Dropbox reported that the requested resource was not found.

Returns whether Dropbox rate-limited the request.

Returns whether retrying the operation may succeed without changing it.

Types

t()

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

Functions

auth?(error)

@spec auth?(term()) :: boolean()

Returns whether an error represents failed authentication or authorization.

conflict?(error)

@spec conflict?(term()) :: boolean()

Returns whether Dropbox reported a path, file, or folder conflict.

integrity?(arg1)

@spec integrity?(term()) :: boolean()

Returns whether an error represents a content integrity mismatch.

new(status, body, headers \\ [])

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"

not_found?(error)

@spec not_found?(term()) :: boolean()

Returns whether Dropbox reported that the requested resource was not found.

rate_limited?(arg1)

@spec rate_limited?(term()) :: boolean()

Returns whether Dropbox rate-limited the request.

retryable?(arg1)

@spec retryable?(term()) :: boolean()

Returns whether retrying the operation may succeed without changing it.