Moss.Error exception (moss v1.6.0)

Copy Markdown

The reason in every {:error, reason} this SDK returns.

code is an atom a caller can match on: :invalid_argument, :not_found, :unauthorized, :network, :deserialization, :model_unavailable or :internal. message is fixed text for each kind of failure and carries no URLs, file paths or index names. detail holds the native core's error text, for logs and support rather than a stable contract, and is nil when there is none.

Moss.Error is an exception, so raise reason works, and it implements String.Chars, so "#{reason}" renders the message.

case Moss.Client.load_index(client, "docs") do
  {:ok, info} -> info
  {:error, %Moss.Error{code: :not_found}} -> nil
end

Summary

Types

code()

@type code() ::
  :invalid_argument
  | :not_found
  | :unauthorized
  | :network
  | :deserialization
  | :model_unavailable
  | :internal

t()

@type t() :: %Moss.Error{
  __exception__: true,
  code: code(),
  detail: String.t() | nil,
  message: String.t()
}