title: How do I debug intermittent errors with CalendarApp?
body: <p>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).</p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Lines 154, 155 and 156 are:</p>
  
  <pre><code>var calendar = CalendarApp.getCalendarById(calendars[region][league]);
  var events = calendar.getEvents(new Date(1900, 1, 1), new Date());
  events.forEach(function (event) { event.deleteEvent(); });
  </code></pre>
  
  <p>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.</p>
  
  <p>These errors appear to be an issue with the availability of CalendarApp, but the <a href="https://script.google.com/dashboard" rel="nofollow">Dashboard</a> does not indicate any issues with the service.</p>
  
  <p>My project key is: <code>MWhWmFSrL1dK3RJui6Aphb12cA4KNgw7R</code></p>