We have a Zap that runs 100's of times per day, and under normal circumstances it usually has a 'Filtered' (Yellow) status in its Task History, and the rest of the time it is 'Success' (Green) status.
The problem I have is trying to catch errors. Inside the Javascript code in this zap there are a lot of API calls, and if any of these API calls fail or cause strange behavior I'd like the Zap to go to a 'Stop' (red) status in the Task History. This will make these incidents more visible in the Task History, and will also provide our developers with email notifications.
I am aware of Filters and how they work, the problem is that this Zap has a Filtered status all day long, 100's of times, so if I were to set up a Filter for errors it would just blend in with all the other tasks that are working perfectly fine. This would also not provide me with email notifications, and once again the notifications would be useless anyways.
An example of an API call from within the Zap:
var fieldKey = "";
var endpoint = pipedriveURL + "dealFields:(key,name)?start=0&api_token=" + pipedriveAPIKey;
var res = await fetch(endpoint, {method: 'GET'});
var resBody = await res.json();
for (var i of resBody.data) {
if (i.name === fieldName) {
fieldKey = i.key;
}
}
// Key not found exit
if (fieldKey === "") {
console.log("Field Key not found in getFieldKeyFromName");
}
If the above code starts to fail for some reason, instead of digging through 100's of tasks trying to read all of these console.log()'s I would like to have them be a little more visible and easy to find with the 'Stopped' (Red) status.
Some API failures will naturally Stop the zap with a Javascript error, but there are other cases where I would like to intentionally Error the Zap's execution. Is this possible?
Sure, you can throw an error like normal:
throw new Error('bad thing')
That'll mark that step of the zap as failed.