-
Notifications
You must be signed in to change notification settings - Fork 29
Turn exceptions into actor failures
Sunny Ripert edited this page Jul 31, 2022
·
3 revisions
By default, errors on inputs will raise an exception, even when using .result
instead of .call
.
If instead you want to mark the actor as failed, you can catch the exception to treat it as an actor failure:
class PlaceOrder < Actor
fail_on ServiceActor::ArgumentError
input :currency, in: ["EUR", "USD"]
# …
end
actor = PlaceOrder.result(currency: nil)
actor.success? # => false
actor.error # => 'Input currency must be included in ["EUR", "USD"] but instead was nil'
You can use fail_on
on any exception you wish to turn into a failure.