Handle errors in a flow

Introduction

The error handling flow is an especial type of flow that allows you to handle errors. If something goes wrong during the execution of a data record, it will be managed by this error handler.

In this example, we are going to set up a simple flow that is going to send an email to a bunch of customers and an error handler that will come into play in case the process fails.

These are the steps that are going to be covered:

  1. Set up our data scheme
  2. Create our interface
  3. Install and configure the needed apps
  4. Build the error handler
  5. Build the flow
  6. Test the process

Set up our data scheme

Our data scheme must basically look as follows:

{
   "name": "",
   "email": ""
}

name: the customer’s name.

email: the customer’s email.

For more information on how to set up our JSON data scheme, please visit this link.

Create our interface

The next step is to set up the structure of the data that our interface will receive and map it against our data scheme.

In this example, we are going to call it email sender and it is going to use exactly the same payload as our data scheme. Our mapping should look as follows:

The scope available must be batch in the authorization tab.

For further information on how to create an interface, please refer to this page.

If you need to know more about how to configure an interface, please visit this post.

Install and configure the needed apps

We need to install and configure these apps:

  1. SMTP Emails: this will send the email to our customers.
  2. SlackChannel: it will send a notification to a Slack channel if an email cannot be sent.

For further information on how to install an app, please refer to this page.

If you need to know more about how to configure an app, please visit this post and if you need more information about how to configure a function, please refer to this link.

Build the error handler

Now we are going to build the flow that will handle errors in our main flow.

This error handler will simply send a notification to a Slack channel with the following text:

Error in Email Sender flow:

Customer: @data.name@
UUID: @system.datarecord.uuid@
HTTP code: @system.error.httpcode@
Task name: @system.error.task_name@
Message: @system.error.message@
Flow name: @system.error.flow_name@
Body: @system.error.body@
Date: @system.error.date@

As you can see in the snippet above, we are going to output some system variables which are provided by the platform.

If you need more information about variables, please visit this link.

Once we have configured the object, we save the flow:

We name it Error Handler and we save it as an error handler by enabling the corresponding switcher as you can see in the screenshot above.

Build the flow

Finally, we build our Email Sender flow which is simply going to send an email.

The receiver information tab in the configuration of this object should look as follows:

Once we have configured the object, we save the flow:

Here we basically choose the error handler that we previously set up.

Test the process

In order to test the process, we are going to send a bunch of customers that are going to receive this email. The email of one of these customers will be empty, so it will cause an error in the flow and therefore it will be handled by the error handler.

In this case, we are going to send the following CURL request in order to insert the batch of records:

curl -X POST \
  https://{{platform_api_url}}/v1/batch \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -H 'X-Apikey: {{put_here_your_api_key}}' \
  -H 'X-App: email_sender' \
  -H 'X-Batch-Status: ready' \
  -H 'X-Flow: Email sender' \
  -H 'X-Scopes: batch' \
  -d '[
	{
          "name": "John Doe",
	  "email": "john.doe@email.com"
	},
	{
	  "name": "Antonio Jesús",
	  "email": ""
	}
]'

You must replace {{platform_api_url}} by the API URL and {{put_here_your_api_key}} by your API key.

This request will insert two records. When the second record is processed, the email function will fail as the email is empty. In this case, our error handler flow will come into play and therefore we will receive the following notification in the Slack channel that we specified:

Congratulations! Now you are successfully handling errors in your flow.