Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Commanded's event handler error/3 callback #12

Merged
merged 2 commits into from
Jul 22, 2018

Conversation

slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented Jul 20, 2018

Allow projectors to return an error tagged tuple ({:error, error}) from a project macro which will cause an error/3 callback function to be called, if defined.

Exceptions when executing the Ecto.Multi will also be rescued and converted into {:error, exception} tuples allowing you to handle in an error/3 function.

Example usage

defmodule ErrorProjector do
  use Commanded.Projections.Ecto, name: "ErrorProjector"

  alias Commanded.Event.FailureContext

  project %ErrorEvent{name: name} do
    {:error, :failed}
  end

  # Skip failed event on error
  def error({:error, _error}, %ErrorEvent{}, %FailureContext{}) do
    :skip
  end
end

Fixes #10.

Allow projectors to return an error tagged tuple (`{:error, error}`) from a `project` macro which will cause an `error/3` callback function to be called, if defined.
@slashdotdash slashdotdash merged commit 6c45cef into master Jul 22, 2018
@slashdotdash slashdotdash deleted the feature/error-callback branch July 22, 2018 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant