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?
We're looking at using Interactor to refactor our controllers. One of the nice things is the clear separation of code to handle
success?
andfailed?
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:
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?