Adding a Step Outcome for Exceptions
- Updated on 09 May 2013
- 2 minutes to read
Even under the best conditions, inputs can be unreliable. To handle missing or invalid data without crashing, steps need paths to account for errors or exceptions. We can add these outcome paths by selecting the Add Outcome for Exception checkbox in the Properties panel and mapping them to steps which can display or otherwise manage errors.
In the example, we will attempt to add an account that already exists in the system using the Add New Account component. When the flow cannot perform this invalid action, rather than stopping, the flow directs to the On Exception path and proceeds to the End Step .
Begin in the Flow Designer's startup window by placing an Add New Account component in the work space. It can be found in the the category Integrations > All Integrations > Internal Services > AccountService . Click Add to place component into the work space.
With the Add New Account step selected, select the Add Outcome for Exception checkbox in the Outcomes section of the Properties panel. This will create a new outcome path on our Add New Account step, called On Exception . Now, whenever the Add New Account step results in an error (say, for example, due to missing inputs), our application's flow will be directed down the On Exception path, rather than Done.
Rather than create additional steps to handle our exception, connect the paths On Exception and Done to the end step, and prevent an exception from occurring in another way.
Exception paths are a necessary part of any flow, but we don't want our flow to follow them except in extreme cases. However, we do want to test our exception path, so we will temporarily remap our inputs to an invalid state. In our application's database, the user account associated with "email@example.com" already exists. We will remap our inputs so that the next time Add New Account runs, it will try to add a user with the same email address, which is an invalid condition.
With the Add New Account 1 selected, from the Properties panel, click the Edit Input Mapping link.
When we view Add New Account 1 in the Mapping Editor, we see that all three inputs are currently empty. To modify the account object, we will change its mapping type from Unknown to Constant . Once we've done this, the account input will expand to include an option for editing its value. Because the input account is an object, this option appears as a rounded button labeled with an ellipses, indicating that it uses an object editor.
Clicking this button reveals all of the properties for the account object input. We can Pick an account or Define the parameters of a new account. In the Define Data section, we can see two fields that are required: EmailAddress and EntityName . We'll fill in the EmailAddress with our invalid value and the EntityName with "QA," for this example.
We set thememberOf and password inputs to ignore and, finally, we save our changes by clicking the Define button. Click OK to exit the Mapping Editor.
Now, when we run our flow in the debugger, we can see that the Add New Account step results in an error, causing our flow to follow the On Exception outcome path. If we want, we can place a variety of display or notification steps to handle this error.