refactor: improved observability in google calendar service (#18147)
This commit is contained in:
1 parent
87b6e0b49c
commit
0d24706380
1 file changed
+10
-1
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { calendar_v3 } from "@googleapis/calendar";
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import type { GaxiosResponse } from "googleapis-common";
|
||||
import { OAuth2Client } from "googleapis-common";
|
||||
import { RRule } from "rrule";
|
||||
import { v4 as uuid } from "uuid";
|
||||
@@ -52,6 +53,9 @@ const ONE_MONTH_IN_MS = 30 * MS_PER_DAY;
|
||||
const GOOGLE_WEBHOOK_URL_BASE = process.env.GOOGLE_WEBHOOK_URL || process.env.NEXT_PUBLIC_WEBAPP_URL;
|
||||
const GOOGLE_WEBHOOK_URL = `${GOOGLE_WEBHOOK_URL_BASE}/api/integrations/googlecalendar/webhook`;
|
||||
|
||||
const isGaxiosResponse = (error: unknown): error is GaxiosResponse<calendar_v3.Schema$Event> =>
|
||||
typeof error === "object" && !!error && error.hasOwnProperty("config");
|
||||
|
||||
export default class GoogleCalendarService implements Calendar {
|
||||
private integrationName = "";
|
||||
private auth: ReturnType<typeof this.initGoogleAuth>;
|
||||
@@ -264,7 +268,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
"primary";
|
||||
|
||||
try {
|
||||
let event;
|
||||
let event: calendar_v3.Schema$Event | undefined;
|
||||
let recurringEventId = null;
|
||||
if (formattedCalEvent.existingRecurringEvent) {
|
||||
recurringEventId = formattedCalEvent.existingRecurringEvent.recurringEventId;
|
||||
@@ -350,6 +354,11 @@ export default class GoogleCalendarService implements Calendar {
|
||||
iCalUID: event?.iCalUID,
|
||||
};
|
||||
} catch (error) {
|
||||
if (isGaxiosResponse(error)) {
|
||||
// Prevent clogging up the logs with the body of the request
|
||||
// Plus, we already have this data in error.data.summary
|
||||
delete error.config.body;
|
||||
}
|
||||
this.log.error(
|
||||
"There was an error creating event in google calendar: ",
|
||||
safeStringify({ error, selectedCalendar, credentialId })
|
||||
|
||||
Reference in new issue
Block a user