Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a 500 error from doPost in Google App Script

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?

like image 706
Fijjit Avatar asked Aug 03 '26 16:08

Fijjit


1 Answers

Answer:

Currently, you cannot force the script to return response codes other than 200.

Issue Tracker:

This has been reported previously in Issue Tracker:

  • Allow scripts to send response codes other than 200

I'd suggest you to star the referenced issue, in order to keep track of it and to help prioritizing it.

Workarounds:

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.

Related question:

  • In Google Apps Script, how can I set the HTTP response code for a service I implement?
like image 114
Iamblichus Avatar answered Aug 07 '26 04:08

Iamblichus