In Code2, if something goes wrong in flow action, by default it will show error message and terminate the flow. If you'd like to show custom error message or trigger another action conditionally, then you can use error handler.
Error handler has following properties:
It only works with previous action's value.
It only works if previous action ends in error.
If previous action succeeds:
Error handler does NOT do anything.
Action after error handler will be triggered.
Let's illustrate with common use case. When user signs up the system sends verification email. If user tries to sign in without clicking verification link, then it will give verification error. We handle this error as follows:
When sign in ends in error it can return one of four codes - verifyError, expireError, wrongUserPass, and notActive. For this tutorial, let's catch first two and show messages accordingly. As you see above, we transform previous action's value and get the code. Then, we show messages in sub flows.
In first message, we inform that user should use active verification link. And in second, we inform that link has expired and a new link has been sent.
There's also default sub flow that works for errors we didn't anticipate.
This whole thing works only if sign in ends in error. If it succeeds, then next action after error handler works. Error handler will be skipped. So, for this case we can add go to page action and redirect to homepage.
Note: At the moment, error handler works with sign in. We'll update other actions soon.