fix(calendar): add error handling for outbound Google Calendar sync (#10696)

Add proper error handling to prevent silent failures when syncing events
to Google Calendar:

- Add .catch() handler in main.ts webhook to log sync failures
- Add try/catch in create() method to log Google API insert errors
- Improve error handling in remove() method to log get/delete errors

Fixes #10535
This commit is contained in:
Rayan Salhab
2026-03-27 11:59:16 +07:00
committed by GitHub
parent a22271d004
commit 82f1647581
2 changed files with 43 additions and 15 deletions
+3 -1
View File
@@ -173,7 +173,9 @@ export const main = async (): Promise<void> => {
res.status(400).send({ err: "'event' or 'workspace' or 'type' is missing" })
return
}
void OutcomingClient.push(ctx, accountClient, workspace, event, type)
void OutcomingClient.push(ctx, accountClient, workspace, event, type).catch((err: any) => {
ctx.error('Outcoming sync failed', { eventId: event.eventId, workspace, type, error: err.message })
})
res.send()
}
}
@@ -153,10 +153,20 @@ export class OutcomingClient {
const calendarId = calendar.externalId
if (calendarId !== undefined) {
await this.rateLimiter.take(1)
await this.calendar.events.insert({
calendarId,
requestBody: body
})
try {
await this.calendar.events.insert({
calendarId,
requestBody: body
})
} catch (err: any) {
this.ctx.error('Google API insert error', {
calendarId,
eventId: event.eventId,
error: err.message,
code: err.code
})
throw err
}
}
}
@@ -380,17 +390,33 @@ export class OutcomingClient {
}
private async remove (eventId: string, calendarId: string): Promise<void> {
const current = await this.calendar.events.get({ calendarId, eventId })
if (current?.data !== undefined) {
if (current.data.organizer?.self === true) {
await this.rateLimiter.take(1)
try {
await this.calendar.events.delete({
eventId,
calendarId
})
} catch {}
try {
const current = await this.calendar.events.get({ calendarId, eventId })
if (current?.data !== undefined) {
if (current.data.organizer?.self === true) {
await this.rateLimiter.take(1)
try {
await this.calendar.events.delete({
eventId,
calendarId
})
} catch (err: any) {
this.ctx.error('Google API delete error', {
calendarId,
eventId,
error: err.message,
code: err.code
})
}
}
}
} catch (err: any) {
this.ctx.error('Failed to get event for deletion', {
calendarId,
eventId,
error: err.message,
code: err.code
})
}
}