How do I debug intermittent errors with CalendarApp?

瘦欲@ 提交于 2019-12-23 03:22:29

问题


I have a Google Apps Script which uses a JSON web API to get a list of StarCraft2 tournaments from a site (using UrlFetchApp) and create corresponding Google Calendar events in a variety of Calendars (one Calendar per region/league combination).

I have a trigger set to every 5 minutes, that emails me immediately on errors, and if the script completes normally and has added any events or run into any errors I caught, it emails me as well.

Most of the time, there are no changes necessary (I cache the JSON info using ScriptDb to avoid calling out to CalendarApp unless I need to) and the script is silent. However, overnight I received several emails which contained the messages:

The resource you requested could not be located. (line 154)

Service error: CalendarApp: Error body {font-family: arial,sans-serif}
G o o g l e     Error   Cannot access the calendar you requested (line 155)

TypeError: Cannot call method "getEvents" of null. (line 155)

Lines 154, 155 and 156 are:

var calendar = CalendarApp.getCalendarById(calendars[region][league]);
var events = calendar.getEvents(new Date(1900, 1, 1), new Date());
events.forEach(function (event) { event.deleteEvent(); });

At this point in the script I've already attempted to add any new events and I'm about to query each of my Calendars to delete any events which occurred in the past.

These errors appear to be an issue with the availability of CalendarApp, but the Dashboard does not indicate any issues with the service.

My project key is: MWhWmFSrL1dK3RJui6Aphb12cA4KNgw7R


回答1:


I have many scripts that use CalendarApp and all of them have occasional errors in their execution, wether in manual mode or time triggered, it seems (but I know this is an empirical feeling) that this service is subject to errors when the traffic is too high or the internet connection is too slow (a few month ago my office had a very poor internet connection and the script used to generate a lot of errors -while it didn't when executed from home-, now that the situation is better the same script runs smoothly everywhere).

Anyway, whatever the real cause might be (and only a Google engineer could answer), the solution I used was to put the Calendar calls in a try-catch loop that tries the connection a few times and since then I have no error notification anymore.

On another script that I didn't change yet, I keep getting errors from time to time but since it doesn't concern critical information I don't really mind... note that I just checked right now and I haven't receive any notification for 5 days ! (must be a good season for calendars ;-)



来源:https://stackoverflow.com/questions/13863155/how-do-i-debug-intermittent-errors-with-calendarapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!