View Source Avalanche.Error exception (Avalanche v0.13.0)
Common application error.
Summary
Functions
Builds an Error struct with a reason of :application_error
.
Formats a Error for printing/logging.
Builds an Error struct with reason and message deived from the given http status.
Returns the Error message.
Creates a new Error from a message string or another error
Builds an Error struct.
Types
@type t() :: %Avalanche.Error{ __exception__: true, message: String.t(), meta: meta(), original_error: any(), reason: atom(), stacktrace: nil | Exception.stacktrace() }
The exception type
Functions
Builds an Error struct with a reason of :application_error
.
Examples:
iex> alias Avalanche.Error
iex> Error.application_error("Bad Things", %{data: "things"})
%Error{__exception__: true, message: "Bad Things", meta: %{data: "things"}, reason: :application_error}
Formats a Error for printing/logging.
This returns a verbose, multi-line string.
Examples:
iex> alias Avalanche.Error
iex> RuntimeError.exception("Failed!") |> Error.new() |> Error.format()
~s<application_error: Failed!
meta: []
original_error: ** (RuntimeError) Failed!>
iex> "Failed!" |> Error.new() |> Error.format()
~s<application_error: Failed!
meta: []
original_error: nil>
iex> 123 |> Error.new() |> Error.format() =~ ~r/original_error: 123/
true
iex> :bad |> Error.new() |> Error.format() =~ ~r/bad/
true
Builds an Error struct with reason and message deived from the given http status.
Examples:
iex> alias Avalanche.Error
iex> Error.http_status(404, %{data: "things"})
%Error{__exception__: true, message: "Not Found", meta: %{data: "things"}, reason: :not_found}
Returns the Error message.
Examples:
iex> alias Avalanche.Error
iex> error = Error.application_error("Bad Things", %{data: "things"})
iex> Error.message(error)
"application_error: Bad Things"
Creates a new Error from a message string or another error
Examples:
# A string will be used as message
iex> alias Avalanche.Error
iex> Error.new("These are the error message")
%Error{message: "These are the error message"}
# Error structs are returned unchanged
iex> Error.new(%Error{reason: :some_reason})
%Error{reason: :some_reason}
# Atoms will be used as reason
iex> Error.new(:some_reason)
%Error{reason: :some_reason}
# Anything else will be used as the `original_error`
iex> Error.new(%RuntimeError{message: "oops!"})
%Error{message: "oops!", original_error: %RuntimeError{message: "oops!"}}
Builds an Error struct.
Examples:
iex> alias Avalanche.Error
iex> Error.new(:bad, "Bad Things", %{data: "things"})
%Error{__exception__: true, message: "Bad Things", meta: %{data: "things"}, reason: :bad}