Reputation: 1467
I have doPost(e) function in an App Script that is called by Zapier. If an exception occurs in my code, a 200 response is sent back to Zapier, but I'd like it to return a 500 error, so that Zapier knows it has failed.
function doPost(e) {
if (e) {
try {
switch (e.parameter.action) {
case 'newOrder':
processNewOrder(e.parameter.orderId, e.parameter.orderType);
break;
case 'cancelledOrder':
processCancelledOrder(e.parameter.orderId, e.parameter.orderType);
break;
}
return ContentService.createTextOutput('Done');
}
catch (err) {
throw err;
}
}
}
How can I return an exception to Zapier in that catch?
Upvotes: 2
Views: 1180
Reputation: 19309
Currently, you cannot force the script to return response codes other than 200.
This has been reported previously in Issue Tracker:
I'd suggest you to star the referenced issue, in order to keep track of it and to help prioritizing it.
Therefore, you'll have to come up with other ways to return information regarding the outcome of the response, like the one suggested by Amit Agarwal. But the response code will always be 200.
Upvotes: 3
Reputation: 11268
Replace:
}
catch (err) {
throw err;
}
}
With:
}
catch (err) {
return ContentService.createTextOutput(err.message);
}
}
Upvotes: 1