Skip to content

Commit f109b55

Browse files
committed
update
1 parent a9f4a28 commit f109b55

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -264,37 +264,39 @@ export default {
264264
let nextSyncToken = null;
265265
let nextPageToken = null;
266266
while (!nextSyncToken) {
267-
const {
268-
data: syncData = {},
269-
status: syncStatus,
270-
} = await this.googleCalendar.listEvents({
271-
returnOnlyData: false,
272-
calendarId,
273-
syncToken,
274-
pageToken: nextPageToken,
275-
maxResults: 2500,
276-
validateStatus: (status) => (status >= 200 && (status < 300 || status == 410)),
277-
});
278-
if (syncStatus === 410) {
279-
console.log("Sync token invalid, resyncing");
280-
nextSyncToken = await this.googleCalendar.fullSync(calendarId);
281-
break;
282-
}
283-
nextPageToken = syncData.nextPageToken;
284-
nextSyncToken = syncData.nextSyncToken;
285-
286-
const { items: events = [] } = syncData;
287-
events
288-
.filter(this.isEventRelevant, this)
289-
.forEach((event) => {
290-
const { status } = event;
291-
if (status === "cancelled") {
292-
console.log("Event cancelled. Exiting.");
293-
return;
294-
}
295-
const meta = this.generateMeta(event);
296-
this.$emit(event, meta);
267+
try {
268+
const { data: syncData = {} } = await this.googleCalendar.listEvents({
269+
returnOnlyData: false,
270+
calendarId,
271+
syncToken,
272+
pageToken: nextPageToken,
273+
maxResults: 2500,
297274
});
275+
276+
nextPageToken = syncData.nextPageToken;
277+
nextSyncToken = syncData.nextSyncToken;
278+
279+
const { items: events = [] } = syncData;
280+
events
281+
.filter(this.isEventRelevant, this)
282+
.forEach((event) => {
283+
const { status } = event;
284+
if (status === "cancelled") {
285+
console.log("Event cancelled. Exiting.");
286+
return;
287+
}
288+
const meta = this.generateMeta(event);
289+
this.$emit(event, meta);
290+
});
291+
} catch (error) {
292+
if (error === "Sync token is no longer valid, a full sync is required.") {
293+
console.log("Sync token invalid, resyncing");
294+
nextSyncToken = await this.googleCalendar.fullSync(calendarId);
295+
break;
296+
} else {
297+
throw error;
298+
}
299+
}
298300
}
299301

300302
this.setNextSyncToken(calendarId, nextSyncToken);

0 commit comments

Comments
 (0)