Error Handling
/- *plugin, ballot, res=resource, inv=invite-store
|%
++ on
|= [=bowl:gall store=state-1:ballot context=[booth-key=@t proposal-key=@t]]
|%
++ action
|= [action-data=json payload=json]
^- action-result
=| result=action-result
:: force an error by:
:: 1) setting the success property to %.n
:: 2) giving a gift back to the booth owner ship (the one on which
:: this custom action is running) with an error reaction/effect
=. success.result %.n
=. effects.result (generate-error "testing custom action error. please ignore.")
:: return the action-result back to Ballot so the gift can be delivered
result
++ generate-error
|= [err=tape]
^- (list card:agent:gall)
=/ context=json
%- pairs:enjs:format
:~
['booth' s+booth-key.context]
['proposal' s+proposal-key.context]
==
=/ error-data=json
%- pairs:enjs:format
:~
['error' s+(crip err)]
==
=/ error-effect=json
%- pairs:enjs:format
:~
['resource' s+'proposal']
['effect' s+'error']
['data' error-data]
==
:: if we assume the custom action was 'invite-member', the error
:: should appears as follows:
=/ effects=json
%- pairs:enjs:format
:~
['action' s+'invite-member-reaction']
['context' context]
['effects' [%a [error-effect]~]]
==
:~ [%give %fact [/booths]~ %json !>(effects)]
==
--
--Last updated