Skip to content

Commit

Permalink
Merge pull request #92 from tourlane/TRIP-13472
Browse files Browse the repository at this point in the history
[chore][TRIP-13472] Add sentry capture exceptions
  • Loading branch information
RubLo authored Aug 28, 2024
2 parents 42a094b + b8d32c8 commit 0715324
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/app-store/googlecalendar/lib/CalendarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class GoogleCalendarService implements Calendar {
// `Failed to refresh access token for Google Calendar: userId: ${credential.userId}`
// );
this.log.error("Error refreshing google token", err);
Sentry.captureException(err);
}
return myGoogleAuth;
};
Expand Down Expand Up @@ -339,7 +340,10 @@ export default class GoogleCalendarService implements Calendar {
},
},
(err, apires) => {
if (err) return reject(err);
if (err) {
Sentry.captureException(err);
return reject(err);
}
// If there's no calendar we just skip
if (!apires?.data.calendars) return resolve([]);
const result = Object.values(apires.data.calendars).reduce((c, i) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/CalendarManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SelectedCalendar } from "@prisma/client";
import * as Sentry from "@sentry/nextjs";
import { createHash } from "crypto";
import _ from "lodash";

Expand Down Expand Up @@ -186,6 +187,12 @@ export const getBusyCalendarTimes = async (
calendars: selectedCalendars,
credentials: withCredentials,
});
Sentry.captureException(error, {
extra: {
calendars: selectedCalendars,
credentials: withCredentials,
},
});
}
return results.reduce((acc, availability) => acc.concat(availability), []);
};
Expand Down
2 changes: 2 additions & 0 deletions packages/features/bookings/lib/handleCancelBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WorkflowMethods,
WorkflowReminder,
} from "@prisma/client";
import * as Sentry from "@sentry/nextjs";
import { NextApiRequest } from "next";

import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
Expand Down Expand Up @@ -182,6 +183,7 @@ async function handler(req: NextApiRequest & { userId?: number }) {
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,
}).catch((e) => {
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}`, e);
Sentry.captureException(e);
})
);
await Promise.all(promises);
Expand Down
14 changes: 13 additions & 1 deletion packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SchedulingType,
WebhookTriggerEvents,
} from "@prisma/client";
import * as Sentry from "@sentry/nextjs";
import async from "async";
import { isValidPhoneNumber } from "libphonenumber-js";
import { cloneDeep } from "lodash";
Expand Down Expand Up @@ -243,10 +244,11 @@ async function ensureAvailableUsers(
} else {
isAvailableToBeBooked = isAvailable(bufferedBusyTimes, input.dateFrom, eventType.length);
}
} catch {
} catch (e) {
log.debug({
message: "Unable set isAvailableToBeBooked. Using true. ",
});
Sentry.captureException(e);
}

if (isAvailableToBeBooked) {
Expand Down Expand Up @@ -311,6 +313,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
log.debug({
message: "Unable set timeOutOfBounds. Using false. ",
});
Sentry.captureException(error);
}

if (timeOutOfBounds) {
Expand Down Expand Up @@ -772,6 +775,9 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
} catch (_err) {
const err = getErrorFromUnknown(_err);
log.error(`Booking ${eventTypeId} failed`, "Error when saving booking to db", err.message);

Sentry.captureException(err);

if (err.code === "P2002") {
throw new HttpError({ statusCode: 409, message: "booking.conflict" });
}
Expand Down Expand Up @@ -1007,6 +1013,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
});
} catch (error) {
log.error("Error while running scheduledJobs for booking", error);
Sentry.captureException(error);
}

try {
Expand Down Expand Up @@ -1041,11 +1048,13 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
smsReminderNumber: booking?.smsReminderNumber || undefined,
}).catch((e) => {
console.error(`Error executing webhook for event: ${eventTrigger}, URL: ${sub.subscriberUrl}`, e);
Sentry.captureException(e);
})
);
await Promise.all(promises);
} catch (error) {
log.error("Error while sending webhook", error);
Sentry.captureException(error);
}
}

Expand All @@ -1067,6 +1076,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
}
} catch (error) {
log.error("Error while updating hashed link", error);
Sentry.captureException(error);
}

if (!booking) throw new HttpError({ statusCode: 400, message: "Booking failed" });
Expand All @@ -1087,6 +1097,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
});
} catch (error) {
log.error("Error while creating booking references", error);
Sentry.captureException(error);
}

try {
Expand All @@ -1100,6 +1111,7 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) {
);
} catch (error) {
log.error("Error while scheduling workflow reminders", error);
Sentry.captureException(error);
}

// booking successful
Expand Down

0 comments on commit 0715324

Please sign in to comment.