Maverick.Exception protocol (Maverick v0.1.0) View Source

A protocol that allows associating http status codes with specific exceptions and providing a fallback operation in the form of an {module, function, arguments} tuple to attempt recovery.

By default, the protocol looks for an implementation on the given exception, then checkds for the :error_code field, or else returns 500 and falls back to returning a JSON-encoded map with the error code and a descriptive error message.

Link to this section Summary

Functions

Receives an exception and returns an HTTP status code.

Receives an exception and returns the fallback operation, represented by a map with an identifying tag (primarily for debugging and logging) and a 3-tuple with the module, function, and arguments to execute to attempt recovery.

Link to this section Types

Specs

fallback() :: %{tag: String.t(), handler: {module(), atom(), list()}}

Specs

t() :: term()

Link to this section Functions

Specs

error_code(t()) :: 100..999

Receives an exception and returns an HTTP status code.

Specs

fallback(t()) :: fallback()

Receives an exception and returns the fallback operation, represented by a map with an identifying tag (primarily for debugging and logging) and a 3-tuple with the module, function, and arguments to execute to attempt recovery.