View Source Dynamo.Error exception (Dynamo v0.2.0)

The single error type returned by every Dynamo operation.

All failures — AWS service errors, transport errors and local validation failures — are normalised into %Dynamo.Error{} at the client boundary, so code above the client never has to inspect raw AWS payloads.

case MyApp.Repo.put(user, condition: "attribute_not_exists(pk)") do
  {:ok, user} -> ...
  {:error, %Dynamo.Error{type: :conditional_check_failed}} -> ...
  {:error, %Dynamo.Error{retryable?: true} = e} -> retry_later(e)
end

Fields

  • :type – categorised atom, e.g. :resource_not_found, :conditional_check_failed, :throttled, :validation_error, :transaction_canceled, :transport_error
  • :message – human readable message
  • :aws_type – the un-namespaced AWS exception name, when applicable
  • :status – HTTP status, when applicable
  • :retryable? – whether retrying the same request may succeed
  • :cancellation_reasons – for :transaction_canceled, one entry per transact item with code, message and item
  • :details – any additional structured data (raw AWS body, exception…)

Summary

Functions

Normalises an AWS error response body (already JSON decoded) plus HTTP status.

Builds a local (non-AWS) error, e.g. a validation failure.

Whether an error of this type is worth retrying.

Wraps a transport level failure (connection refused, timeout…).

Builds a :validation_error.

Types

t()

@type t() :: %Dynamo.Error{
  __exception__: term(),
  aws_type: String.t() | nil,
  cancellation_reasons: [map()] | nil,
  details: term(),
  message: String.t(),
  retryable?: boolean(),
  status: non_neg_integer() | nil,
  type: atom()
}

Functions

from_aws(body, status)

@spec from_aws(map() | binary(), non_neg_integer()) :: t()

Normalises an AWS error response body (already JSON decoded) plus HTTP status.

Handles both "__type" forms DynamoDB uses ("ResourceNotFoundException" and "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException") and both message keys ("message" and "Message").

new(type, message, opts \\ [])

@spec new(atom(), String.t(), keyword()) :: t()

Builds a local (non-AWS) error, e.g. a validation failure.

retryable?(error)

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

Whether an error of this type is worth retrying.

transport(reason)

@spec transport(term()) :: t()

Wraps a transport level failure (connection refused, timeout…).

validation(message, details \\ nil)

@spec validation(String.t(), term()) :: t()

Builds a :validation_error.