#call
,#call_and_raise
, and#call!
now accept an optional keyword parameter calledvalidate
. This will skip validations if passedfalse
. (true
is the default value.)#call!
now takes advantage of thevalidate:
parameter internally to avoid running validations twice.
#call!
now raises the underlying exception if the service threw an exception, rather than hiding it inside aCivilService::ServiceFailure
.
CivilService::MultiResultService::MultiResult#exception
now checks the underlying exception on the root result object, in case the service threw an exception.
- Services now have a new
#call_and_raise
method, which will return a result object on failure but will raise exceptions that are thrown inside the service call (effectively, the behavior of#call
in CivilService 1.0.0). - Added a new mixin called
CivilService::MultiResultService
, which allows creating services whose results are composed of multiple results that are aggregated together.
CivilService::Result#errors
now always returns an Errors object even if it hasn't been explicitly set.
-
BREAKING CHANGE: The behavior of
CivilService::Service#call
has changed when exceptions are raised inside the service. Thecall
method will now catch the exception and return a failing result object, with the exception message as an error on:base
.The behavior of
call!
has not changed: a failing result will be raised as aCivilService::ServiceFailure
exception, and an exception thrown inside the service will not be caught (and therefore will be raised to the caller).The idea of this change is that the behaviors of
call
andcall!
are now predictable:call
will (almost) never raise an exception, whereascall!
can raise an exception.The exception to this rule (pun intended, always intend your puns) is that
call
will not catch exceptions that don't inherit fromStandardError
, such asSystemExit
. See Honeybadger's explanation of why this is a good idea. -
CivilService::Result
now has an additional attribute calledexception
, which can be used to retrieve an exception thrown inside acall
method.