Configuring failure conditions
While configuring Rest API/GraphQL Api/Database Query
, there might be scenario where you want your connector response to execute failure flow instead of success flow on certain conditions, in such cases, you can define failure conditions
.
Failure conditions can be located under Connectors -> ADD API/ADD QUERY -> Response -> FAILURE CONDITION
It consists of three parts -
Field | Description | Keyword |
---|---|---|
Failure Condition | It accepts the inline js code within {{}} and should output either true/false . For eg - {{OUTPUT.RESP == 1}} | - |
Failure Message | Custom failure message that can be displayed to your end user | FAILURE_MESSAGE |
Failure/Error code | Custom Error Code that you can define to identify the failure condition. For eg - LICENSE_ERR , NOT_FOUND . No space or special characters are allowed except underscore. | FAILURE_CODE |
- You can define multiple failure conditions based on your use case.
- Above Keywords you can use in
Error
leg of above connector added inAction Flow
Configuring Failure Conditions
Failure Conditions can be configured for any Api/Query, you have have added.
Let's add a failure condition to a Database Query
-
In the above condition, if the given email is not present in the database then we will return a custom error code NO_DATA
along with custom error message.
Now, lets use this query in our app.
Using Failure conditions in BIND Data to Control
Let's have two text input control named - customeremail
and customername
for entering Customer Email and Customer Full name respectively. So, when we enter an email in customeremail
control, we want our query to get executed and get us Customer Full Name that gets populated in customername
control.
For Data bind option for customername
control, we have a data query using Connector Lirary -> Customer -> GetCustomerByEmail
and assign customeremail
as input to Email
dynamic variable for this query.
Now, when there is no Customer info for given email id then your custom failure message will be visible to end user of your app.
Here, in case of success scenario, no error message is visible and Customer data is displayed.
Using Failure conditions in Action flow
We can utilize the same query for calling it in action flow which gets triggered on, button_click
event of a button control.
Let's have one text input control named - customeremail
and one button control named - getcustomername
.
Now, on button_click
event of this button, we will call Customers -> GetCustomerByEmail
Query with customeremail
as input parameter. We then show Customer Name
retrieved from the above query response in a customername
Text Input control in case of a Success
response. In case of an Error
response we will show a failure message using a Toast
action. Error leg will either be called for non 2xx Status Code
response or based on Failure Conditions
specified for this query. In this case, failure condition will get called when it returns empty value if given email id is not present in the Database.
Here, Error_Message
is output variable that will be configured in failure scenario and Name
is the output variable that will be configured in success scenario for set customername
control's value.
Success flow showing Customer Name in customername
control -
Error flow showing Failure message
when No customer is found for given email id
-
FAILURE_MESSAGE
and FAILURE_CODE
are the two keywords that you can use in output variables when failure conditions is met and Error Leg is executed for Connector Action block.