Exop.Fallback behaviour (Exop v1.4.4) View Source

Provides macros for fallback handling.


defmodule FallbackModule do
  use Exop.Fallback

  def process(operation, params, error) do
    # your error handling code here

defmodule TestOperation do
  use Exop.Operation

  fallback FallbackModule, return: true

  parameter :a, type: :integer
  parameter :b, type: :integer

  def process(%{a: a, b: b}), do: a + b

# TestOperation.run(a: 1, b: "2") => :some_fallback_result

By using Exop.Fallback you need to implement process/3 function which takes following params:

  • failed operation module (TestOperation in the example above)
  • params that were passed into the operation (%{a: 1, b: "2"})
  • an error result which was returned by the operation ({:error, {:validation, %{a: ["has wrong type"]}}})

During a fallback definition you can add return: true option so in the example case TestOperation.run/1 will return the result of the fallback (FallbackModule.process/3 function's result - :some_fallback_result). If you want TestOperation.run/1 to return original result ({:error, {:validation, %{a: ["has wrong type"]}}}) specify return: false option or just omit it in a fallback definition.

Link to this section Summary


Fallback handling function. Receives

Link to this section Types


t() :: Exop.Fallback

Link to this section Callbacks


process(atom(), map(), any()) :: any()

Fallback handling function. Receives:

  • failed operation module
  • a map of parameters with which the operation was invoked
  • an error tuple returned by the operation