collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Multiple kinds of failure #165

Open benthorner opened 5 years ago

benthorner commented 5 years ago

We're looking at using Interactor to refactor our controllers. One of the nice things is the clear separation of code to handle success? and failed? cases.

Sometimes we may have interactors that can fail in multiple ways, where the code to handle the failed? case might be different, depending on the kind of failure.

One way of approaching this might be like this:

# in the interactor
context.fail(error: :error_type_1)

# in the controller
if result.failed? && result.error == :error_type_1
   # handle this kind of error e.g. render instead of redirect

It would be convenient if you could do something like if result.failed?(error: :error_type_1). Would you consider adding such a feature to the gem?