Skip to content

Commit e0f8c14

Browse files
Utilize reportOverallFailure to continue after failed API calls (#467)
1 parent aeb4e64 commit e0f8c14

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

Helpers.gs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,15 @@ function processEvent(event, calendarTz){
610610
if (modifyExistingEvents){
611611
oldEvent = calendarEvents[index]
612612
Logger.log("Updating existing event " + newEvent.extendedProperties.private["id"]);
613-
newEvent = callWithBackoff(function(){
614-
return Calendar.Events.update(newEvent, targetCalendarId, calendarEvents[index].id);
615-
}, defaultMaxRetries);
613+
try{
614+
newEvent = callWithBackoff(function(){
615+
return Calendar.Events.update(newEvent, targetCalendarId, calendarEvents[index].id);
616+
}, defaultMaxRetries);
617+
}
618+
catch (e){
619+
Logger.log(`Operation failed with error "${e}"`);
620+
reportOverallFailure = true;
621+
}
616622
if (newEvent != null && emailSummary){
617623
modifiedEvents.push([[oldEvent.summary, newEvent.summary, oldEvent.start.date||oldEvent.start.dateTime, newEvent.start.date||newEvent.start.dateTime, oldEvent.end.date||oldEvent.end.dateTime, newEvent.end.date||newEvent.end.dateTime, oldEvent.location, newEvent.location, oldEvent.description, newEvent.description], targetCalendarName]);
618624
}
@@ -621,9 +627,15 @@ function processEvent(event, calendarTz){
621627
else{
622628
if (addEventsToCalendar){
623629
Logger.log("Adding new event " + newEvent.extendedProperties.private["id"]);
624-
newEvent = callWithBackoff(function(){
625-
return Calendar.Events.insert(newEvent, targetCalendarId);
626-
}, defaultMaxRetries);
630+
try{
631+
newEvent = callWithBackoff(function(){
632+
return Calendar.Events.insert(newEvent, targetCalendarId);
633+
}, defaultMaxRetries);
634+
}
635+
catch (e){
636+
Logger.log(`Operation failed with error "${e}"`);
637+
reportOverallFailure = true;
638+
}
627639
if (newEvent != null && emailSummary){
628640
addedEvents.push([[newEvent.summary, newEvent.start.date||newEvent.start.dateTime, newEvent.end.date||newEvent.end.dateTime, newEvent.location, newEvent.description], targetCalendarName]);
629641
}
@@ -918,9 +930,15 @@ function processEventCleanup(){
918930
)
919931
{
920932
Logger.log("Deleting old event " + currentID);
921-
callWithBackoff(function(){
922-
Calendar.Events.remove(targetCalendarId, calendarEvents[i].id);
923-
}, defaultMaxRetries);
933+
try{
934+
callWithBackoff(function(){
935+
Calendar.Events.remove(targetCalendarId, calendarEvents[i].id);
936+
}, defaultMaxRetries);
937+
}
938+
catch (e){
939+
Logger.log(`Operation failed with error "${e}"`);
940+
reportOverallFailure = true;
941+
}
924942

925943
if (emailSummary){
926944
removedEvents.push([[calendarEvents[i].summary, calendarEvents[i].start.date||calendarEvents[i].start.dateTime, calendarEvents[i].end.date||calendarEvents[i].end.dateTime, calendarEvents[i].location, calendarEvents[i].description], targetCalendarName]);

0 commit comments

Comments
 (0)