Bolty.Error exception (Bolty v0.4.0)

Copy Markdown View Source

Summary

Types

A decoded Bolt FAILURE.

t()

Functions

Return the code for the given error.

Gets the corresponding atom based on the error code.

Types

bolt_failure()

@type bolt_failure() :: %{
  :code => atom() | binary(),
  :message => binary() | nil,
  optional(:gql_status) => binary(),
  optional(:description) => binary(),
  optional(:diagnostic_record) => map(),
  optional(:cause) => bolt_failure()
}

A decoded Bolt FAILURE.

code/message are always present — message being the server's human diagnostic. The rest arrive only on a GQL FAILURE (Bolt 5.7+):

  • gql_status — the GQLSTATUS code, e.g. "42001"
  • description — the standard description of that status class. Generic by design; pair it with gql_status, don't read it as the diagnostic.
  • diagnostic_record_classification, and _position for a syntax error
  • cause — the underlying failure, same shape, often a more precise status

t()

@type t() :: %Bolty.Error{
  __exception__: term(),
  bolt: bolt_failure() | nil,
  code: atom(),
  module: module(),
  packstream: %{bits: any() | nil} | nil
}

Functions

message(error)

@spec message(t()) :: String.t()

Return the code for the given error.

Examples

 iex> {:error, %Bolty.Error{} = error} = do_something()
 iex> Exception.message(error)
 "Unable to perform this action."

to_atom(code)

@spec to_atom(String.t() | atom()) :: atom()

Gets the corresponding atom based on the error code.

An atom code is already resolved and passes through unchanged; this lets callers build an error map with a known atom code (e.g. %{code: :unsupported_message_version, message: ...}) without it being collapsed to :unknown by the string lookup.

wrap(module, code)

@spec wrap(module(), atom()) :: t()
@spec wrap(module(), String.t()) :: t()
@spec wrap(module(), map()) :: t()
@spec wrap(
  module(),
  {:tls_alert, {atom(), any()}}
) :: t()
@spec wrap(module(), tuple()) :: t()

wrap(module, code, packstream)

@spec wrap(any(), any(), any()) :: t()