0

I have code that works well in one worksheet but not another. Comes out:

"Exception: Sorry, a server error occurred. Please wait a moment and try again."

Maybe I'm calling UrlFetchApp too many times... is there a way to call UrlFetchApp once for what I'm looking for based on my code? On the sheet where the code works fine it returns the response message and all 3 files in a Drive folder.

var exchange = UrlFetchApp.fetch('https://www.myweb.com/', options);
var response = exchange.getContentText();
var cell = ss.getRange('A5');
cell.setValue(response);
var URL = response.match(/link\|(.+)\|/)[1];
var url1 = URL + '.pdf';
var url2 = URL + '.xml';
var url3 = URL + '.cdr';
var pdf = UrlFetchApp.fetch(url1).getBlob().setName(name + '.pdf');
var xml = UrlFetchApp.fetch(url2).getBlob().setName(name + '.xml');
var cdr = UrlFetchApp.fetch(url3).getBlob().setName(name + '.cdr');
var folder = DriveApp.getFolderById('myfolder');
folder.createFile(pdf);
folder.createFile(xml);
folder.createFile(cdr);
  • 1
    Server error is usually exactly what they mean - just wait some time and you should be fine. Happens from time to time. – roma Jun 19 '20 at 18:01
  • But the code works on another sheet at the same time, that is, the server seems to work correctly and at the same time, it is very rare. – J. Kenneth Reátegui B. Jun 19 '20 at 18:08
  • 1
    Different sheet might be hosted on different servers, even different continents. So, no correlation in these errors for a pack of scripts. This errors are rare indeed, you can treat them as app script server downtime. – roma Jun 19 '20 at 18:20
  • Well, you have clarified the matter for me anyway. Thank you! – J. Kenneth Reátegui B. Jun 19 '20 at 18:23
  • to expand on what @roma said - check the [quotas](https://developers.google.com/apps-script/guides/services/quotas) docs to know which are in effect and what the error messages might look like - quota errors have very specific messages – Oleg Valter is with Ukraine Jun 20 '20 at 07:24
  • Also - possible duplicate of [this Q&A](https://stackoverflow.com/questions/18804649/google-apps-script-were-sorry-a-server-error-occurred-please-wait-a-bit-and). Try wrapping `response.match` into a `try...catch` statement, if it works, I will mark as duplicate. Sometimes you cause an error under the hood, and this message just points you to that fact – Oleg Valter is with Ukraine Jun 20 '20 at 07:30

1 Answers1

0

I fixed it, it looks like it was a conflict with one of the versions of the spreadsheet history. What I did was generate a copy of the file and there were no more error messages. The script is fully functional. Thanks for the contributions.