From dafb55f7938fe146168112048f4463cff7bc1b56 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Sat, 11 Nov 2023 03:06:56 +0530 Subject: [PATCH 01/16] feat: booking errors logging --- apps/web/public/static/locales/en/common.json | 2 ++ packages/app-store/alby/lib/PaymentService.ts | 6 ++-- .../app-store/paypal/lib/PaymentService.ts | 8 ++--- .../stripepayment/lib/PaymentService.ts | 16 ++++++---- .../BookEventForm/BookEventForm.tsx | 29 ++++++++++++++----- .../features/bookings/lib/handleNewBooking.ts | 5 ++-- packages/lib/logger.ts | 4 +++ 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index e9054ee1348cb7..f215d15d98e444 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -56,6 +56,8 @@ "a_refund_failed": "A refund failed", "awaiting_payment_subject": "Awaiting Payment: {{title}} on {{date}}", "meeting_awaiting_payment": "Your meeting is awaiting payment", + "payment_not_created_error":"Payment could not be created", + "couldnt_charge_card_error":"Could not charge card for Payment", "help": "Help", "price": "Price", "paid": "Paid", diff --git a/packages/app-store/alby/lib/PaymentService.ts b/packages/app-store/alby/lib/PaymentService.ts index f008063bd61e18..d284ca4bf28908 100644 --- a/packages/app-store/alby/lib/PaymentService.ts +++ b/packages/app-store/alby/lib/PaymentService.ts @@ -36,7 +36,7 @@ export class PaymentService implements IAbstractPaymentService { }, }); if (!booking || !this.credentials?.account_lightning_address) { - throw new Error(); + throw new Error("Ably: Booking or Lightning address not found"); } const uid = uuidv4(); @@ -80,8 +80,8 @@ export class PaymentService implements IAbstractPaymentService { } return paymentData; } catch (error) { - console.error(error); - throw new Error("Payment could not be created"); + log.error("Ably: Payment could not be created", bookingId); + throw new Error("payment_not_created_error"); } } async update(): Promise { diff --git a/packages/app-store/paypal/lib/PaymentService.ts b/packages/app-store/paypal/lib/PaymentService.ts index 4566431acba29a..4810058a4eaa7e 100644 --- a/packages/app-store/paypal/lib/PaymentService.ts +++ b/packages/app-store/paypal/lib/PaymentService.ts @@ -87,8 +87,8 @@ export class PaymentService implements IAbstractPaymentService { } return paymentData; } catch (error) { - console.error(error); - throw new Error("Payment could not be created"); + log.error("Paypal: Payment could not be created for bookingId", bookingId); + throw new Error("payment_not_created_error"); } } async update(): Promise { @@ -166,8 +166,8 @@ export class PaymentService implements IAbstractPaymentService { } return paymentData; } catch (error) { - console.error(error); - throw new Error("Payment could not be created"); + log.error("Paypal: Payment method could not be collected for bookingId", bookingId); + throw new Error("Paypal: Payment method could not be collected"); } } chargeCard( diff --git a/packages/app-store/stripepayment/lib/PaymentService.ts b/packages/app-store/stripepayment/lib/PaymentService.ts index 559b8a2908329f..b8c0a309931fdf 100644 --- a/packages/app-store/stripepayment/lib/PaymentService.ts +++ b/packages/app-store/stripepayment/lib/PaymentService.ts @@ -129,7 +129,8 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { console.error(`Payment could not be created for bookingId ${bookingId}`, error); - throw new Error("Payment could not be created"); + log.error("Stripe: Payment could not be created", bookingId, JSON.stringify(error)); + throw new Error("payment_not_created_error"); } } @@ -199,8 +200,12 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { - console.error(`Payment method could not be collected for bookingId ${bookingId}`, error); - throw new Error("Payment could not be created"); + log.error( + "Stripe: Payment method could not be collected for bookingId", + bookingId, + JSON.stringify(error) + ); + throw new Error("Stripe: Payment method could not be collected"); } } @@ -278,7 +283,8 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { console.error(`Could not charge card for payment ${payment.id}`, error); - throw new Error("Payment could not be created"); + log.error("Stripe: Could not charge card for paymentd", bookingId, JSON.stringify(error)); + throw new Error("couldnt_charge_card_error"); } } @@ -369,7 +375,7 @@ export class PaymentService implements IAbstractPaymentService { await this.stripe.paymentIntents.cancel(payment.externalId, { stripeAccount }); return true; } catch (e) { - console.error(e); + log.error("Stripe: Unable to delete Payment in stripe of paymentId", bookingId, JSON.stringify(e)); return false; } } diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index afec8ed37cb45d..3540e5beebbdb0 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -28,7 +28,6 @@ import { useBookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect"; import { MINUTES_TO_BOOK } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery"; -import { HttpError } from "@calcom/lib/http-error"; import { trpc } from "@calcom/trpc"; import { Alert, Button, EmptyScreen, Form, showToast } from "@calcom/ui"; import { Calendar } from "@calcom/ui/components/icon"; @@ -153,6 +152,7 @@ export const BookEventFormChild = ({ const verifiedEmail = useBookerStore((state) => state.verifiedEmail); const setVerifiedEmail = useBookerStore((state) => state.setVerifiedEmail); const bookingSuccessRedirect = useBookingSuccessRedirect(); + const [responseVercelIdHeader, setResponseVercelIdHeader] = useState(null); const router = useRouter(); const { t, i18n } = useLocale(); @@ -220,7 +220,12 @@ export const BookEventFormChild = ({ booking: responseData, }); }, - onError: () => { + onError: (err, variables, ctx) => { + const headers = ctx?.response?.headers; + const vercelId = headers?.get("x-vercel-id"); + if (vercelId) { + setResponseVercelIdHeader(vercelId); + } errorRef && errorRef.current?.scrollIntoView({ behavior: "smooth" }); }, }); @@ -390,7 +395,8 @@ export const BookEventFormChild = ({ bookingForm.formState.errors["globalError"], createBookingMutation, createRecurringBookingMutation, - t + t, + responseVercelIdHeader )} /> @@ -438,17 +444,26 @@ const getError = ( bookingMutation: UseMutationResult, // eslint-disable-next-line @typescript-eslint/no-explicit-any recurringBookingMutation: UseMutationResult, - t: TFunction + t: TFunction, + responseVercelIdHeader: string | null ) => { if (globalError) return globalError.message; const error = bookingMutation.error || recurringBookingMutation.error; + console.log("ERROR_IN_BOOK_EVENT_FORM", bookingMutation, error); - return error instanceof HttpError || error instanceof Error ? ( - <>{t("can_you_try_again")} + return error.message ? ( + <> + {responseVercelIdHeader ?? ""} {error.message} + ) : ( - "Unknown error" + <>{t("can_you_try_again")} ); + // return error instanceof HttpError || error instanceof Error ? ( + // <>{t("can_you_try_again")} + // ) : ( + // "Unknown error" + // ); }; function useInitialFormValues({ diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 2537730da8ec15..9076e03c66d804 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -680,10 +680,11 @@ async function handler( const fullName = getFullName(bookerName); + // Why are we only using "en" locale const tGuests = await getTranslation("en", "common"); const dynamicUserList = Array.isArray(reqBody.user) ? reqBody.user : getUsernameList(reqBody.user); - if (!eventType) throw new HttpError({ statusCode: 404, message: "eventType.notFound" }); + if (!eventType) throw new HttpError({ statusCode: 404, message: "EventType not Found" }); const isTeamEventType = !!eventType.schedulingType && ["COLLECTIVE", "ROUND_ROBIN"].includes(eventType.schedulingType); @@ -2683,7 +2684,7 @@ const findBookingQuery = async (bookingId: number) => { // This should never happen but it's just typescript safe if (!foundBooking) { - throw new Error("Internal Error."); + throw new Error("Internal Error. Couldn't found booking"); } // Don't leak any sensitive data diff --git a/packages/lib/logger.ts b/packages/lib/logger.ts index 4d6d4be3c67bfc..51ae157f9a450d 100644 --- a/packages/lib/logger.ts +++ b/packages/lib/logger.ts @@ -16,4 +16,8 @@ const logger = new Logger({ }, }); +export const setRequestId = (requestId: string | undefined) => { + logger.context.requestId = requestId; +}; + export default logger; From 957dd65afb88f9abe41488e1b35a2ec2ef43e5dc Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Sun, 12 Nov 2023 01:32:40 +0530 Subject: [PATCH 02/16] chore: add more logs --- apps/web/public/static/locales/en/common.json | 5 +++++ packages/core/CalendarManager.ts | 22 +++++++++++++++++-- packages/core/getUserAvailability.ts | 2 +- .../BookEventForm/BookEventForm.tsx | 8 +------ .../features/bookings/lib/handleNewBooking.ts | 12 ++++++---- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index f215d15d98e444..91dda24bf0aa9e 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -58,6 +58,11 @@ "meeting_awaiting_payment": "Your meeting is awaiting payment", "payment_not_created_error":"Payment could not be created", "couldnt_charge_card_error":"Could not charge card for Payment", + "no_available_users_found_error":"No available users found. Could you try another time slot?", + "request_body_end_time_internal_error":"Internal Error. Request body does not contain end time", + "create_calendar_event_error":"Unable to create Calendar event in Organizer's calendar", + "update_calendar_event_error":"Unable to update Calendar event.", + "delete_calendar_event_error":"Unable to delete Calendar event.", "help": "Help", "price": "Price", "paid": "Paid", diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 5d9f0252eeae12..a2b052df7c489e 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -206,7 +206,7 @@ export const getBusyCalendarTimes = async ( selectedCalendars: SelectedCalendar[] ) => { let results: EventBusyDate[][] = []; - const months = getMonths(dateFrom, dateTo); + // const months = getMonths(dateFrom, dateTo); try { // Subtract 11 hours from the start date to avoid problems in UTC- time zones. const startDate = dayjs(dateFrom).subtract(11, "hours").format(); @@ -277,6 +277,7 @@ export const createEvent = async ( calError, }) ); + throw new Error("create_calendar_event_error"); } log.debug( "Created calendar event", @@ -348,6 +349,20 @@ export const updateEvent = async ( }) : undefined; + if (!updatedResult) { + logger.error( + "updateEvent failed", + safeStringify({ + success, + bookingRefUid, + credential: getPiiFreeCredential(credential), + originalEvent: getPiiFreeCalendarEvent(calEvent), + calError, + }) + ); + throw new Error("update_calendar_event_error"); + } + if (Array.isArray(updatedResult)) { calWarnings = updatedResult.flatMap((res) => res.additionalInfo?.calWarnings ?? []); } else { @@ -388,12 +403,15 @@ export const deleteEvent = async ({ if (calendar) { return calendar.deleteEvent(bookingRefUid, event, externalCalendarId); } else { - log.warn( + log.error( "Could not do deleteEvent - No calendar adapter found", safeStringify({ credential: getPiiFreeCredential(credential), + event, }) ); + + throw new Error("delete_calendar_event_error"); } return Promise.resolve({}); diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts index 5843005e203692..3c4f77497b67ac 100644 --- a/packages/core/getUserAvailability.ts +++ b/packages/core/getUserAvailability.ts @@ -164,7 +164,7 @@ export const getUserAvailability = async function getUsersWorkingHoursLifeTheUni const user = initialData?.user || (await getUser(where)); - if (!user) throw new HttpError({ statusCode: 404, message: "No user found" }); + if (!user) throw new HttpError({ statusCode: 404, message: "No user found in getUserAvailability" }); log.debug( "getUserAvailability for user", safeStringify({ user: { id: user.id }, slot: { dateFrom, dateTo } }) diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index 3540e5beebbdb0..ddefad0d8cb508 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -450,20 +450,14 @@ const getError = ( if (globalError) return globalError.message; const error = bookingMutation.error || recurringBookingMutation.error; - console.log("ERROR_IN_BOOK_EVENT_FORM", bookingMutation, error); return error.message ? ( <> - {responseVercelIdHeader ?? ""} {error.message} + {responseVercelIdHeader ?? ""} {t(error.message)} ) : ( <>{t("can_you_try_again")} ); - // return error instanceof HttpError || error instanceof Error ? ( - // <>{t("can_you_try_again")} - // ) : ( - // "Unknown error" - // ); }; function useInitialFormValues({ diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 9076e03c66d804..8443f801171368 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -6,6 +6,7 @@ import { isValidPhoneNumber } from "libphonenumber-js"; import { cloneDeep } from "lodash"; import type { NextApiRequest } from "next"; import short, { uuid } from "short-uuid"; +import type { Logger } from "tslog"; import { v5 as uuidv5 } from "uuid"; import z from "zod"; @@ -364,7 +365,8 @@ async function ensureAvailableUsers( eventType: Awaited> & { users: IsFixedAwareUser[]; }, - input: { dateFrom: string; dateTo: string; timeZone: string; originalRescheduledBooking?: BookingType } + input: { dateFrom: string; dateTo: string; timeZone: string; originalRescheduledBooking?: BookingType }, + loggerWithEventDetails: Logger ) { const availableUsers: IsFixedAwareUser[] = []; const duration = dayjs(input.dateTo).diff(input.dateFrom, "minute"); @@ -416,7 +418,8 @@ async function ensureAvailableUsers( } } if (!availableUsers.length) { - throw new Error("No available users found."); + loggerWithEventDetails.error(`No available users found.`); + throw new Error("no_available_users_found_error"); } return availableUsers; } @@ -539,7 +542,7 @@ async function getBookingData({ return true; }; if (!reqBodyWithEnd(reqBody)) { - throw new Error("Internal Error."); + throw new Error("request_body_end_time_internal_error"); } // reqBody.end is no longer an optional property. if ("customInputs" in reqBody) { @@ -925,7 +928,8 @@ async function handler( dateTo: dayjs(reqBody.end).tz(reqBody.timeZone).format(), timeZone: reqBody.timeZone, originalRescheduledBooking, - } + }, + loggerWithEventDetails ); const luckyUsers: typeof users = []; From a1a133aa3adb5303d6c89e990897e536b73ff66c Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Sun, 12 Nov 2023 02:06:46 +0530 Subject: [PATCH 03/16] fix: imports --- packages/app-store/alby/lib/PaymentService.ts | 3 +++ packages/app-store/paypal/lib/PaymentService.ts | 3 +++ packages/app-store/stripepayment/lib/PaymentService.ts | 3 +++ packages/lib/logger.ts | 4 ---- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/app-store/alby/lib/PaymentService.ts b/packages/app-store/alby/lib/PaymentService.ts index d284ca4bf28908..56cc2f855e3f37 100644 --- a/packages/app-store/alby/lib/PaymentService.ts +++ b/packages/app-store/alby/lib/PaymentService.ts @@ -3,12 +3,15 @@ import type { Booking, Payment, PaymentOption, Prisma } from "@prisma/client"; import { v4 as uuidv4 } from "uuid"; import type z from "zod"; +import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; import type { CalendarEvent } from "@calcom/types/Calendar"; import type { IAbstractPaymentService } from "@calcom/types/PaymentService"; import { albyCredentialKeysSchema } from "./albyCredentialKeysSchema"; +const log = logger.getSubLogger({ prefix: ["payment-service:ably"] }); + export class PaymentService implements IAbstractPaymentService { private credentials: z.infer | null; diff --git a/packages/app-store/paypal/lib/PaymentService.ts b/packages/app-store/paypal/lib/PaymentService.ts index 4810058a4eaa7e..0befcbb30fa83b 100644 --- a/packages/app-store/paypal/lib/PaymentService.ts +++ b/packages/app-store/paypal/lib/PaymentService.ts @@ -4,12 +4,15 @@ import z from "zod"; import Paypal from "@calcom/app-store/paypal/lib/Paypal"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; import type { CalendarEvent } from "@calcom/types/Calendar"; import type { IAbstractPaymentService } from "@calcom/types/PaymentService"; import { paymentOptionEnum } from "../zod"; +const log = logger.getSubLogger({ prefix: ["payment-service:paypal"] }); + export const paypalCredentialKeysSchema = z.object({ client_id: z.string(), secret_key: z.string(), diff --git a/packages/app-store/stripepayment/lib/PaymentService.ts b/packages/app-store/stripepayment/lib/PaymentService.ts index b8c0a309931fdf..fd93b6395cd275 100644 --- a/packages/app-store/stripepayment/lib/PaymentService.ts +++ b/packages/app-store/stripepayment/lib/PaymentService.ts @@ -5,6 +5,7 @@ import z from "zod"; import { sendAwaitingPaymentEmail } from "@calcom/emails"; import { getErrorFromUnknown } from "@calcom/lib/errors"; +import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; import type { CalendarEvent } from "@calcom/types/Calendar"; import type { IAbstractPaymentService } from "@calcom/types/PaymentService"; @@ -14,6 +15,8 @@ import { createPaymentLink } from "./client"; import { retrieveOrCreateStripeCustomerByEmail } from "./customer"; import type { StripePaymentData, StripeSetupIntentData } from "./server"; +const log = logger.getSubLogger({ prefix: ["payment-service:stripe"] }); + export const stripeCredentialKeysSchema = z.object({ stripe_user_id: z.string(), default_currency: z.string(), diff --git a/packages/lib/logger.ts b/packages/lib/logger.ts index 51ae157f9a450d..4d6d4be3c67bfc 100644 --- a/packages/lib/logger.ts +++ b/packages/lib/logger.ts @@ -16,8 +16,4 @@ const logger = new Logger({ }, }); -export const setRequestId = (requestId: string | undefined) => { - logger.context.requestId = requestId; -}; - export default logger; From ad0eb2d9d7a1cadc30003e7319aa71958eb14b23 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Sun, 12 Nov 2023 02:16:14 +0530 Subject: [PATCH 04/16] chore: type errors --- packages/app-store/stripepayment/lib/PaymentService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-store/stripepayment/lib/PaymentService.ts b/packages/app-store/stripepayment/lib/PaymentService.ts index fd93b6395cd275..506370450c772e 100644 --- a/packages/app-store/stripepayment/lib/PaymentService.ts +++ b/packages/app-store/stripepayment/lib/PaymentService.ts @@ -286,7 +286,7 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { console.error(`Could not charge card for payment ${payment.id}`, error); - log.error("Stripe: Could not charge card for paymentd", bookingId, JSON.stringify(error)); + log.error("Stripe: Could not charge card for paymentd", _bookingId, JSON.stringify(error)); throw new Error("couldnt_charge_card_error"); } } @@ -378,7 +378,7 @@ export class PaymentService implements IAbstractPaymentService { await this.stripe.paymentIntents.cancel(payment.externalId, { stripeAccount }); return true; } catch (e) { - log.error("Stripe: Unable to delete Payment in stripe of paymentId", bookingId, JSON.stringify(e)); + log.error("Stripe: Unable to delete Payment in stripe of paymentId", paymentId, JSON.stringify(e)); return false; } } From f74c19d510cc9f7d98d8be3da69d764f6e29621c Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Sun, 12 Nov 2023 13:54:16 +0530 Subject: [PATCH 05/16] chore: add seat bookng error --- apps/web/public/static/locales/en/common.json | 1 + packages/features/bookings/lib/handleNewBooking.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 91dda24bf0aa9e..336288f8986a74 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -63,6 +63,7 @@ "create_calendar_event_error":"Unable to create Calendar event in Organizer's calendar", "update_calendar_event_error":"Unable to update Calendar event.", "delete_calendar_event_error":"Unable to delete Calendar event.", + "already_signed_up_for_this_booking_error":"You are already signed up for this booking.", "help": "Help", "price": "Price", "paid": "Paid", diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 8443f801171368..144f5747293f01 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -1277,7 +1277,7 @@ async function handler( booking.attendees.find((attendee) => attendee.email === invitee[0].email) && dayjs.utc(booking.startTime).format() === evt.startTime ) { - throw new HttpError({ statusCode: 409, message: "Already signed up for this booking." }); + throw new HttpError({ statusCode: 409, message: "already_signed_up_for_this_booking_error" }); } // There are two paths here, reschedule a booking with seats and booking seats without reschedule From 8f268e6845bfdd0f2a5133fea06868736bb540fe Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Tue, 14 Nov 2023 01:48:57 +0530 Subject: [PATCH 06/16] chore: add ErrorCoes --- apps/web/public/static/locales/en/common.json | 1 + packages/app-store/alby/lib/PaymentService.ts | 3 ++- packages/app-store/paypal/lib/PaymentService.ts | 3 ++- .../app-store/stripepayment/lib/PaymentService.ts | 3 ++- packages/core/CalendarManager.ts | 7 ++++--- .../Booker/components/BookEventForm/BookEventForm.tsx | 4 +++- packages/features/bookings/lib/handleNewBooking.ts | 11 +++++++---- packages/lib/errorCodes.ts | 11 +++++++++++ 8 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 packages/lib/errorCodes.ts diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 05e087259d23d1..7cad30997badf9 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -64,6 +64,7 @@ "update_calendar_event_error":"Unable to update Calendar event.", "delete_calendar_event_error":"Unable to delete Calendar event.", "already_signed_up_for_this_booking_error":"You are already signed up for this booking.", + "hosts_unavailable_for_booking":"Some of the hosts are unavailable for booking.", "help": "Help", "price": "Price", "paid": "Paid", diff --git a/packages/app-store/alby/lib/PaymentService.ts b/packages/app-store/alby/lib/PaymentService.ts index 56cc2f855e3f37..6b9863c35ed7b1 100644 --- a/packages/app-store/alby/lib/PaymentService.ts +++ b/packages/app-store/alby/lib/PaymentService.ts @@ -3,6 +3,7 @@ import type { Booking, Payment, PaymentOption, Prisma } from "@prisma/client"; import { v4 as uuidv4 } from "uuid"; import type z from "zod"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; import type { CalendarEvent } from "@calcom/types/Calendar"; @@ -84,7 +85,7 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { log.error("Ably: Payment could not be created", bookingId); - throw new Error("payment_not_created_error"); + throw new Error(ErrorCode.PaymentCreationFailure); } } async update(): Promise { diff --git a/packages/app-store/paypal/lib/PaymentService.ts b/packages/app-store/paypal/lib/PaymentService.ts index 0befcbb30fa83b..9b6d479d099108 100644 --- a/packages/app-store/paypal/lib/PaymentService.ts +++ b/packages/app-store/paypal/lib/PaymentService.ts @@ -4,6 +4,7 @@ import z from "zod"; import Paypal from "@calcom/app-store/paypal/lib/Paypal"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; import type { CalendarEvent } from "@calcom/types/Calendar"; @@ -91,7 +92,7 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { log.error("Paypal: Payment could not be created for bookingId", bookingId); - throw new Error("payment_not_created_error"); + throw new Error(ErrorCode.PaymentCreationFailure); } } async update(): Promise { diff --git a/packages/app-store/stripepayment/lib/PaymentService.ts b/packages/app-store/stripepayment/lib/PaymentService.ts index 506370450c772e..cbe699242a363c 100644 --- a/packages/app-store/stripepayment/lib/PaymentService.ts +++ b/packages/app-store/stripepayment/lib/PaymentService.ts @@ -4,6 +4,7 @@ import { v4 as uuidv4 } from "uuid"; import z from "zod"; import { sendAwaitingPaymentEmail } from "@calcom/emails"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import logger from "@calcom/lib/logger"; import prisma from "@calcom/prisma"; @@ -287,7 +288,7 @@ export class PaymentService implements IAbstractPaymentService { } catch (error) { console.error(`Could not charge card for payment ${payment.id}`, error); log.error("Stripe: Could not charge card for paymentd", _bookingId, JSON.stringify(error)); - throw new Error("couldnt_charge_card_error"); + throw new Error(ErrorCode.ChargeCardFailure); } } diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index a2b052df7c489e..711c4993238bd2 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -6,6 +6,7 @@ import { getCalendar } from "@calcom/app-store/_utils/getCalendar"; import getApps from "@calcom/app-store/utils"; import dayjs from "@calcom/dayjs"; import { getUid } from "@calcom/lib/CalEventParser"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import logger from "@calcom/lib/logger"; import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData"; import { safeStringify } from "@calcom/lib/safeStringify"; @@ -277,7 +278,7 @@ export const createEvent = async ( calError, }) ); - throw new Error("create_calendar_event_error"); + throw new Error(ErrorCode.CreateCalendarEventFailure); } log.debug( "Created calendar event", @@ -360,7 +361,7 @@ export const updateEvent = async ( calError, }) ); - throw new Error("update_calendar_event_error"); + throw new Error(ErrorCode.UpdateCalendarEventFailure); } if (Array.isArray(updatedResult)) { @@ -411,7 +412,7 @@ export const deleteEvent = async ({ }) ); - throw new Error("delete_calendar_event_error"); + throw new Error(ErrorCode.DeleteCalendarEventFailure); } return Promise.resolve({}); diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index ddefad0d8cb508..7a39f23bd4a5c6 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -220,7 +220,9 @@ export const BookEventFormChild = ({ booking: responseData, }); }, - onError: (err, variables, ctx) => { + onError: (err, _, ctx) => { + console.log("response", err.response); + // TODO: Fix this type error const headers = ctx?.response?.headers; const vercelId = headers?.get("x-vercel-id"); if (vercelId) { diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index de477e003669fe..50fb62220e4da2 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -53,6 +53,7 @@ import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/ import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib"; import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser"; import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import getPaymentAppData from "@calcom/lib/getPaymentAppData"; import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType"; @@ -417,7 +418,7 @@ async function ensureAvailableUsers( } if (!availableUsers.length) { loggerWithEventDetails.error(`No available users found.`); - throw new Error("no_available_users_found_error"); + throw new Error(ErrorCode.NoAvailableUsersFound); } return availableUsers; } @@ -540,7 +541,7 @@ async function getBookingData({ return true; }; if (!reqBodyWithEnd(reqBody)) { - throw new Error("request_body_end_time_internal_error"); + throw new Error(ErrorCode.RequestBodyWithouEnd); } // reqBody.end is no longer an optional property. if ("customInputs" in reqBody) { @@ -631,6 +632,8 @@ async function handler( ) { const { userId } = req; + throw new Error("hey"); + // handle dynamic user let eventType = !req.body.eventTypeId && !!req.body.eventTypeSlug @@ -951,7 +954,7 @@ async function handler( if ( availableUsers.filter((user) => user.isFixed).length !== users.filter((user) => user.isFixed).length ) { - throw new Error("Some of the hosts are unavailable for booking."); + throw new Error(ErrorCode.HostsUnavailableForBooking); } // Pushing fixed user before the luckyUser guarantees the (first) fixed user as the organizer. users = [...availableUsers.filter((user) => user.isFixed), ...luckyUsers]; @@ -1269,7 +1272,7 @@ async function handler( booking.attendees.find((attendee) => attendee.email === invitee[0].email) && dayjs.utc(booking.startTime).format() === evt.startTime ) { - throw new HttpError({ statusCode: 409, message: "already_signed_up_for_this_booking_error" }); + throw new HttpError({ statusCode: 409, message: ErrorCode.AlreadySignedUpForBooking }); } // There are two paths here, reschedule a booking with seats and booking seats without reschedule diff --git a/packages/lib/errorCodes.ts b/packages/lib/errorCodes.ts new file mode 100644 index 00000000000000..4595afd9227f1f --- /dev/null +++ b/packages/lib/errorCodes.ts @@ -0,0 +1,11 @@ +export enum ErrorCode { + CreateCalendarEventFailure = "create_calendar_event_error", + PaymentCreationFailure = "payment_not_created_error", + NoAvailableUsersFound = "no_available_users_found_error", + ChargeCardFailure = "couldnt_charge_card_error", + RequestBodyWithouEnd = "request_body_end_time_internal_error", + UpdateCalendarEventFailure = "update_calendar_event_error", + DeleteCalendarEventFailure = "delete_calendar_event_error", + AlreadySignedUpForBooking = "already_signed_up_for_this_booking_error", + HostsUnavailableForBooking = "hosts_unavailable_for_booking", +} From 083b8d79207ed44d2bd78f61b0e60e7b6e3ef2ac Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Tue, 14 Nov 2023 01:52:34 +0530 Subject: [PATCH 07/16] chore: remove log --- packages/features/bookings/lib/handleNewBooking.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 50fb62220e4da2..55b8e2b2d6b95a 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -632,8 +632,6 @@ async function handler( ) { const { userId } = req; - throw new Error("hey"); - // handle dynamic user let eventType = !req.body.eventTypeId && !!req.body.eventTypeSlug From 28b30d70e2927062cae6aeccef44daed5bb625df Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 15:57:30 +0530 Subject: [PATCH 08/16] chore: small fixes --- apps/web/public/static/locales/en/common.json | 1 + packages/app-store/alby/lib/PaymentService.ts | 6 +++--- packages/app-store/stripepayment/lib/PaymentService.ts | 3 +-- packages/features/bookings/lib/handleNewBooking.ts | 4 ++-- packages/lib/errorCodes.ts | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 7cad30997badf9..adc2822bee7c6a 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1370,6 +1370,7 @@ "event_name_info": "The event type name", "event_date_info": "The event date", "event_time_info": "The event start time", + "event_type_not_found":"EventType not Found", "location_info": "The location of the event", "additional_notes_info": "The additional notes of booking", "attendee_name_info": "The person booking's name", diff --git a/packages/app-store/alby/lib/PaymentService.ts b/packages/app-store/alby/lib/PaymentService.ts index 6b9863c35ed7b1..9974f1aa2522e2 100644 --- a/packages/app-store/alby/lib/PaymentService.ts +++ b/packages/app-store/alby/lib/PaymentService.ts @@ -11,7 +11,7 @@ import type { IAbstractPaymentService } from "@calcom/types/PaymentService"; import { albyCredentialKeysSchema } from "./albyCredentialKeysSchema"; -const log = logger.getSubLogger({ prefix: ["payment-service:ably"] }); +const log = logger.getSubLogger({ prefix: ["payment-service:alby"] }); export class PaymentService implements IAbstractPaymentService { private credentials: z.infer | null; @@ -40,7 +40,7 @@ export class PaymentService implements IAbstractPaymentService { }, }); if (!booking || !this.credentials?.account_lightning_address) { - throw new Error("Ably: Booking or Lightning address not found"); + throw new Error("Alby: Booking or Lightning address not found"); } const uid = uuidv4(); @@ -84,7 +84,7 @@ export class PaymentService implements IAbstractPaymentService { } return paymentData; } catch (error) { - log.error("Ably: Payment could not be created", bookingId); + log.error("Alby: Payment could not be created", bookingId); throw new Error(ErrorCode.PaymentCreationFailure); } } diff --git a/packages/app-store/stripepayment/lib/PaymentService.ts b/packages/app-store/stripepayment/lib/PaymentService.ts index cbe699242a363c..ed8d1bb3e96a3b 100644 --- a/packages/app-store/stripepayment/lib/PaymentService.ts +++ b/packages/app-store/stripepayment/lib/PaymentService.ts @@ -286,8 +286,7 @@ export class PaymentService implements IAbstractPaymentService { return paymentData; } catch (error) { - console.error(`Could not charge card for payment ${payment.id}`, error); - log.error("Stripe: Could not charge card for paymentd", _bookingId, JSON.stringify(error)); + log.error("Stripe: Could not charge card for payment", _bookingId, JSON.stringify(error)); throw new Error(ErrorCode.ChargeCardFailure); } } diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 55b8e2b2d6b95a..ffd7394b07e6da 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -680,7 +680,7 @@ async function handler( const tGuests = await getTranslation("en", "common"); const dynamicUserList = Array.isArray(reqBody.user) ? reqBody.user : getUsernameList(reqBody.user); - if (!eventType) throw new HttpError({ statusCode: 404, message: "EventType not Found" }); + if (!eventType) throw new HttpError({ statusCode: 404, message: "event_type_not_found" }); const isTeamEventType = !!eventType.schedulingType && ["COLLECTIVE", "ROUND_ROBIN"].includes(eventType.schedulingType); @@ -2681,7 +2681,7 @@ const findBookingQuery = async (bookingId: number) => { // This should never happen but it's just typescript safe if (!foundBooking) { - throw new Error("Internal Error. Couldn't found booking"); + throw new Error("Internal Error. Couldn't find booking"); } // Don't leak any sensitive data diff --git a/packages/lib/errorCodes.ts b/packages/lib/errorCodes.ts index 4595afd9227f1f..7d0205c94ef6ca 100644 --- a/packages/lib/errorCodes.ts +++ b/packages/lib/errorCodes.ts @@ -8,4 +8,5 @@ export enum ErrorCode { DeleteCalendarEventFailure = "delete_calendar_event_error", AlreadySignedUpForBooking = "already_signed_up_for_this_booking_error", HostsUnavailableForBooking = "hosts_unavailable_for_booking", + EventTypeNotFound = "event_type_not_found_error", } From f83892a72e2aa9b92de8e03b4afcfcb063dbfd48 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 16:00:05 +0530 Subject: [PATCH 09/16] fix: remove calendar event error --- packages/core/CalendarManager.ts | 3 --- packages/lib/errorCodes.ts | 3 --- 2 files changed, 6 deletions(-) diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 711c4993238bd2..5f7d92c737a3a4 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -278,7 +278,6 @@ export const createEvent = async ( calError, }) ); - throw new Error(ErrorCode.CreateCalendarEventFailure); } log.debug( "Created calendar event", @@ -411,8 +410,6 @@ export const deleteEvent = async ({ event, }) ); - - throw new Error(ErrorCode.DeleteCalendarEventFailure); } return Promise.resolve({}); diff --git a/packages/lib/errorCodes.ts b/packages/lib/errorCodes.ts index 7d0205c94ef6ca..07c51ae693b6fe 100644 --- a/packages/lib/errorCodes.ts +++ b/packages/lib/errorCodes.ts @@ -1,11 +1,8 @@ export enum ErrorCode { - CreateCalendarEventFailure = "create_calendar_event_error", PaymentCreationFailure = "payment_not_created_error", NoAvailableUsersFound = "no_available_users_found_error", ChargeCardFailure = "couldnt_charge_card_error", RequestBodyWithouEnd = "request_body_end_time_internal_error", - UpdateCalendarEventFailure = "update_calendar_event_error", - DeleteCalendarEventFailure = "delete_calendar_event_error", AlreadySignedUpForBooking = "already_signed_up_for_this_booking_error", HostsUnavailableForBooking = "hosts_unavailable_for_booking", EventTypeNotFound = "event_type_not_found_error", From 14fbb0b8ea3babf6c46b6947f50dd87a907f46a5 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 16:46:42 +0530 Subject: [PATCH 10/16] chore: comment --- .../components/BookEventForm/BookEventForm.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx index 7a39f23bd4a5c6..ebbbdeeb45077d 100644 --- a/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx +++ b/packages/features/bookings/Booker/components/BookEventForm/BookEventForm.tsx @@ -221,13 +221,11 @@ export const BookEventFormChild = ({ }); }, onError: (err, _, ctx) => { - console.log("response", err.response); - // TODO: Fix this type error - const headers = ctx?.response?.headers; - const vercelId = headers?.get("x-vercel-id"); - if (vercelId) { - setResponseVercelIdHeader(vercelId); - } + // TODO: + // const vercelId = ctx?.meta?.headers?.get("x-vercel-id"); + // if (vercelId) { + // setResponseVercelIdHeader(vercelId); + // } errorRef && errorRef.current?.scrollIntoView({ behavior: "smooth" }); }, }); From 368d8d4e56d7cdba207bb1ab829f4f010b75e0c2 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 18:06:21 +0530 Subject: [PATCH 11/16] chore: remove unused --- packages/core/CalendarManager.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 5f7d92c737a3a4..7648d3c015be1c 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -6,7 +6,6 @@ import { getCalendar } from "@calcom/app-store/_utils/getCalendar"; import getApps from "@calcom/app-store/utils"; import dayjs from "@calcom/dayjs"; import { getUid } from "@calcom/lib/CalEventParser"; -import { ErrorCode } from "@calcom/lib/errorCodes"; import logger from "@calcom/lib/logger"; import { getPiiFreeCalendarEvent, getPiiFreeCredential } from "@calcom/lib/piiFreeData"; import { safeStringify } from "@calcom/lib/safeStringify"; @@ -360,7 +359,6 @@ export const updateEvent = async ( calError, }) ); - throw new Error(ErrorCode.UpdateCalendarEventFailure); } if (Array.isArray(updatedResult)) { From 317eae0d744750f92d0a43c594017834c1d9145e Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 18:33:10 +0530 Subject: [PATCH 12/16] fix: tests --- apps/api/test/lib/bookings/_post.test.ts | 3 ++- packages/features/bookings/lib/handleNewBooking.ts | 1 + .../lib/handleNewBooking/test/fresh-booking.test.ts | 7 ++++--- .../lib/handleNewBooking/test/recurring-event.test.ts | 3 ++- .../test/team-bookings/collective-scheduling.test.ts | 3 ++- packages/lib/server/defaultResponder.ts | 9 ++++++++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/api/test/lib/bookings/_post.test.ts b/apps/api/test/lib/bookings/_post.test.ts index a6a308c6f81091..64abddcfe3462b 100644 --- a/apps/api/test/lib/bookings/_post.test.ts +++ b/apps/api/test/lib/bookings/_post.test.ts @@ -8,6 +8,7 @@ import { describe, expect, test, vi } from "vitest"; import dayjs from "@calcom/dayjs"; import sendPayload from "@calcom/features/webhooks/lib/sendPayload"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { buildBooking, buildEventType, buildWebhook } from "@calcom/lib/test/builder"; import prisma from "@calcom/prisma"; @@ -148,7 +149,7 @@ describe.skipIf(true)("POST /api/bookings", () => { expect(res._getStatusCode()).toBe(500); expect(JSON.parse(res._getData())).toEqual( expect.objectContaining({ - message: "No available users found.", + message: ErrorCode.NoAvailableUsersFound, }) ); }); diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index ffd7394b07e6da..cb9550683d0091 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -632,6 +632,7 @@ async function handler( ) { const { userId } = req; + throw new Error("Not implemented"); // handle dynamic user let eventType = !req.body.eventTypeId && !!req.body.eventTypeSlug diff --git a/packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts b/packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts index ea085f421a3bb7..d79c3ad26df0f3 100644 --- a/packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts +++ b/packages/features/bookings/lib/handleNewBooking/test/fresh-booking.test.ts @@ -13,6 +13,7 @@ import { describe, expect } from "vitest"; import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { resetTestEmails } from "@calcom/lib/testEmails"; import { BookingStatus } from "@calcom/prisma/enums"; import { test } from "@calcom/web/test/fixtures/fixtures"; @@ -1025,7 +1026,7 @@ describe("handleNewBooking", () => { }); await expect(async () => await handleNewBooking(req)).rejects.toThrowError( - "No available users found" + ErrorCode.NoAvailableUsersFound ); }, timeout @@ -1112,7 +1113,7 @@ describe("handleNewBooking", () => { }); await expect(async () => await handleNewBooking(req)).rejects.toThrowError( - "No available users found" + ErrorCode.NoAvailableUsersFound ); }, timeout @@ -1240,7 +1241,7 @@ describe("handleNewBooking", () => { * NOTE: We might want to think about making the bookings get ACCEPTED automatically if the booker is the organizer of the event-type. This is a design decision it seems for now. */ test( - `should make a fresh booking in PENDING state even when the booker is the organizer of the event-type + `should make a fresh booking in PENDING state even when the booker is the organizer of the event-type 1. Should create a booking in the database with status PENDING 2. Should send emails to the booker as well as organizer for booking request and awaiting approval 3. Should trigger BOOKING_REQUESTED webhook diff --git a/packages/features/bookings/lib/handleNewBooking/test/recurring-event.test.ts b/packages/features/bookings/lib/handleNewBooking/test/recurring-event.test.ts index bcf811e1e94290..5eb7d31207d4d2 100644 --- a/packages/features/bookings/lib/handleNewBooking/test/recurring-event.test.ts +++ b/packages/features/bookings/lib/handleNewBooking/test/recurring-event.test.ts @@ -2,6 +2,7 @@ import { v4 as uuidv4 } from "uuid"; import { describe, expect } from "vitest"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import logger from "@calcom/lib/logger"; import { BookingStatus } from "@calcom/prisma/enums"; import { test } from "@calcom/web/test/fixtures/fixtures"; @@ -369,7 +370,7 @@ describe("handleNewBooking", () => { }), }); - expect(() => handleRecurringEventBooking(req, res)).rejects.toThrow("No available users found"); + expect(() => handleRecurringEventBooking(req, res)).rejects.toThrow(ErrorCode.NoAvailableUsersFound); // Actually the first booking goes through in this case but the status is still a failure. We should do a dry run to check if booking is possible for the 2 slots and if yes, then only go for the actual booking otherwise fail the recurring bookign }, timeout diff --git a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts index e5d7ce7191c333..883db267da7a91 100644 --- a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts +++ b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts @@ -4,6 +4,7 @@ import { describe, expect } from "vitest"; import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData"; import { WEBAPP_URL } from "@calcom/lib/constants"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { SchedulingType } from "@calcom/prisma/enums"; import { BookingStatus } from "@calcom/prisma/enums"; import { test } from "@calcom/web/test/fixtures/fixtures"; @@ -667,7 +668,7 @@ describe("handleNewBooking", () => { await expect(async () => { await handleNewBooking(req); - }).rejects.toThrowError("No available users found."); + }).rejects.toThrowError(ErrorCode.NoAvailableUsersFound); }, timeout ); diff --git a/packages/lib/server/defaultResponder.ts b/packages/lib/server/defaultResponder.ts index b70f99cd04dc75..5effa92f2f7b39 100644 --- a/packages/lib/server/defaultResponder.ts +++ b/packages/lib/server/defaultResponder.ts @@ -20,7 +20,14 @@ export function defaultResponder(f: Handle) { console.error(err); const error = getServerErrorFromUnknown(err); res.statusCode = error.statusCode; - res.json({ message: error.message }); + // const responseVercelIdHeader = + // typeof req.headers?.get === "function" + // ? !!req.headers.get("x-vercel-id") + // : !!(req.headers as { [key: string]: string })?.["x-vercel-id"]; + const responseVercelIdHeader = "DL4CM"; + console.log({ responseVercelIdHeader }); + + res.json({ message: error.message, responseVercelIdHeader }); } finally { performance.mark("End"); performance.measure(`[${ok ? "OK" : "ERROR"}][$1] ${req.method} '${req.url}'`, "Start", "End"); From 5502f66cddfcdce646d67a47f46c8a9a17436909 Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 18:42:02 +0530 Subject: [PATCH 13/16] chore --- packages/features/bookings/lib/handleNewBooking.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index cb9550683d0091..ffd7394b07e6da 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -632,7 +632,6 @@ async function handler( ) { const { userId } = req; - throw new Error("Not implemented"); // handle dynamic user let eventType = !req.body.eventTypeId && !!req.body.eventTypeSlug From f1a1565ccec37948e7b569962c93da059292c94f Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 20:52:33 +0530 Subject: [PATCH 14/16] fix: test collective scheduling --- .../test/team-bookings/collective-scheduling.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts index 883db267da7a91..eb43bb8b67dad3 100644 --- a/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts +++ b/packages/features/bookings/lib/handleNewBooking/test/team-bookings/collective-scheduling.test.ts @@ -355,7 +355,7 @@ describe("handleNewBooking", () => { await expect(async () => { await handleNewBooking(req); - }).rejects.toThrowError("Some of the hosts are unavailable for booking"); + }).rejects.toThrowError(ErrorCode.HostsUnavailableForBooking); }, timeout ); From b0fcf293fe2750435180c35a0efd64818d5d70ac Mon Sep 17 00:00:00 2001 From: Udit Takkar Date: Wed, 15 Nov 2023 23:11:13 +0530 Subject: [PATCH 15/16] chore: undo change --- packages/lib/server/defaultResponder.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/lib/server/defaultResponder.ts b/packages/lib/server/defaultResponder.ts index 5effa92f2f7b39..b70f99cd04dc75 100644 --- a/packages/lib/server/defaultResponder.ts +++ b/packages/lib/server/defaultResponder.ts @@ -20,14 +20,7 @@ export function defaultResponder(f: Handle) { console.error(err); const error = getServerErrorFromUnknown(err); res.statusCode = error.statusCode; - // const responseVercelIdHeader = - // typeof req.headers?.get === "function" - // ? !!req.headers.get("x-vercel-id") - // : !!(req.headers as { [key: string]: string })?.["x-vercel-id"]; - const responseVercelIdHeader = "DL4CM"; - console.log({ responseVercelIdHeader }); - - res.json({ message: error.message, responseVercelIdHeader }); + res.json({ message: error.message }); } finally { performance.mark("End"); performance.measure(`[${ok ? "OK" : "ERROR"}][$1] ${req.method} '${req.url}'`, "Start", "End"); From 4fe5d0b97504369de6f23ca3f223f3f780e26240 Mon Sep 17 00:00:00 2001 From: zomars Date: Wed, 15 Nov 2023 12:14:15 -0700 Subject: [PATCH 16/16] Update common.json --- apps/web/public/static/locales/en/common.json | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 73b18f2929f4f6..94506cb885a2ea 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -56,15 +56,15 @@ "a_refund_failed": "A refund failed", "awaiting_payment_subject": "Awaiting Payment: {{title}} on {{date}}", "meeting_awaiting_payment": "Your meeting is awaiting payment", - "payment_not_created_error":"Payment could not be created", - "couldnt_charge_card_error":"Could not charge card for Payment", - "no_available_users_found_error":"No available users found. Could you try another time slot?", - "request_body_end_time_internal_error":"Internal Error. Request body does not contain end time", - "create_calendar_event_error":"Unable to create Calendar event in Organizer's calendar", - "update_calendar_event_error":"Unable to update Calendar event.", - "delete_calendar_event_error":"Unable to delete Calendar event.", - "already_signed_up_for_this_booking_error":"You are already signed up for this booking.", - "hosts_unavailable_for_booking":"Some of the hosts are unavailable for booking.", + "payment_not_created_error": "Payment could not be created", + "couldnt_charge_card_error": "Could not charge card for Payment", + "no_available_users_found_error": "No available users found. Could you try another time slot?", + "request_body_end_time_internal_error": "Internal Error. Request body does not contain end time", + "create_calendar_event_error": "Unable to create Calendar event in Organizer's calendar", + "update_calendar_event_error": "Unable to update Calendar event.", + "delete_calendar_event_error": "Unable to delete Calendar event.", + "already_signed_up_for_this_booking_error": "You are already signed up for this booking.", + "hosts_unavailable_for_booking": "Some of the hosts are unavailable for booking.", "help": "Help", "price": "Price", "paid": "Paid", @@ -1372,7 +1372,7 @@ "event_name_info": "The event type name", "event_date_info": "The event date", "event_time_info": "The event start time", - "event_type_not_found":"EventType not Found", + "event_type_not_found": "EventType not Found", "location_info": "The location of the event", "additional_notes_info": "The additional notes of booking", "attendee_name_info": "The person booking's name",