Why the 500 Internal Server Error all sudden

Viewed 708

I have App Scripts on Google Sheets that I have across my clients. They have a copy of it and individual app scripts on their GS.

Everything has been working fine until the last few days.

I am getting this '500 Internal Server Error' on a POST call to the script for no reason - on something that worked fine before. To fix the issue I go and publish the script again which creates a NEW URL (that is nuisance) and I have to then take the NEW URL and plug it into the app for that client. What a mess.

First why is this happening where these script URLs are going into an internal server error now? This was not happening before. I have at least 30 installs right now and growing. And this error is just random.

How can I fix this?

Errors:

Level
Type    Description Date
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbyJC-oXU9k5ijJc7vlvmT3xWNOZLBfl6RjjNqSU/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
14 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
17 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
21 hours ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbyJC-oXU9k5ijJc7vlvmT3xWNOZLBfl6RjjNqSU/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago
Error
Dynamic Block   
Server error: `POST https://script.google.com/macros/s/AKfycbwmwyNADRdyBT6PUEBcuwv17EsQBTpTjfVwRbFpUw/exec` resulted in a `500 Internal Server Error` response: <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehl (truncated...)
2 days ago

Code:

function doPost(e) {

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[2]);

  var data = sheet.getDataRange().getValues();

  var sub_json = JSON.parse(e.postData.contents);

  var zip = sub_json.custom_fields.CS_Intent.toLowerCase() 

  var area = []

  area = check_area(data,zip);

  if (area[0] != '') {
    return buildUpdateCUF(area);
  }
  else
  {
    return notFound() 
  }
}

//=====================================================================================================
//  Pull the City Name and State Name from Google Sheets if we find a match to the zip code entered 
//=====================================================================================================

function check_area(data,zip) {

  var areaName = '';
  var areaState = '';

  for (var i = 1; i < data.length; i++) {

    var zipCode = data[i][0].toString()

    if (zip.indexOf(zipCode)>-1) {
      areaName =  data[i][1]
      areaState =  data[i][2]
    }

    var cityName = data[i][1].toString().toLowerCase() 

    if (zip.indexOf(cityName)>-1) {
      areaName =  data[i][1]
      areaState =  data[i][2]
    }

  }
  return [areaName,areaState] 
}


//=====================================================================================================
//  Build the ManyChat Actions JSON to Add the Tag and update CUFs
//=====================================================================================================


function buildUpdateCUF(area) {
  var output = JSON.stringify({
  version: "v2",
  content: {
    "actions": [  
         { 
          "action": "add_tag",
          "tag_name": "CS_Service_Area_Yes"
         },
         {
          "action": "set_field_value",
          "field_name": "CS_City",
          "value": area[0]
         },
         {
          "action": "set_field_value",
          "field_name": "CS_State",
          "value": area[1]
         }
     ] 
  }
});

  return ContentService.createTextOutput(output).setMimeType(ContentService.MimeType.JSON);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Could not find zip code in service area
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


function notFound() {
  var output = JSON.stringify({
    version: "v2",
    content: {
    "actions": [  
         { 
          "action": "remove_tag",
          "tag_name": "CS_Service_Area_Yes"
         }
     ] 
  }
});
  return ContentService.createTextOutput(output).setMimeType(ContentService.MimeType.JSON);
}  
0 Answers
Related