From 1cdc97dd3753ca643e974eaa5ab01ccf014817ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efra=C3=ADn=20Roch=C3=ADn?= Date: Thu, 23 Mar 2023 11:03:49 -0700 Subject: [PATCH] Add detailed error logs to handleNewBooking (#7907) * Add logs to get more context on "No user available" error * remove nit --- .../features/bookings/lib/handleNewBooking.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 20f86852d5..9a58d26c54 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -143,6 +143,9 @@ const isWithinAvailableHours = ( return true; } } + log.error( + `NAUF: isWithinAvailableHours ${JSON.stringify({ ...timeSlot, organizerTimeZone, workingHours })}` + ); return false; }; @@ -158,10 +161,22 @@ function checkForConflicts(busyTimes: BufferedBusyTimes, time: dayjs.ConfigType, const endTime = dayjs(busyTime.end); // Check if time is between start and end times if (dayjs(time).isBetween(startTime, endTime, null, "[)")) { + log.error( + `NAUF: start between a busy time slot ${JSON.stringify({ + ...busyTime, + time: dayjs(time).format(), + })}` + ); return true; } // Check if slot end time is between start and end time if (dayjs(time).add(length, "minutes").isBetween(startTime, endTime)) { + log.error( + `NAUF: Ends between a busy time slot ${JSON.stringify({ + ...busyTime, + time: dayjs(time).add(length, "minutes").format(), + })}` + ); return true; } // Check if startTime is between slot @@ -537,14 +552,14 @@ async function handler( periodCountCalendarDays: eventType.periodCountCalendarDays, }); } catch (error) { + log.warn({ + message: "NewBooking: Unable set timeOutOfBounds. Using false. ", + }); if (error instanceof BookingDateInPastError) { // TODO: HttpError should not bleed through to the console. log.info(`Booking eventType ${eventTypeId} failed`, error); throw new HttpError({ statusCode: 400, message: error.message }); } - log.debug({ - message: "Unable set timeOutOfBounds. Using false. ", - }); } if (timeOutOfBounds) { @@ -552,7 +567,9 @@ async function handler( errorCode: "BookingTimeOutOfBounds", message: `EventType '${eventType.eventName}' cannot be booked at this time.`, }; - + log.warn({ + message: `NewBooking: EventType '${eventType.eventName}' cannot be booked at this time.`, + }); throw new HttpError({ statusCode: 400, message: error.message }); } @@ -583,6 +600,7 @@ async function handler( const isDynamicAllowed = !users.some((user) => !user.allowDynamicBooking); if (!isDynamicAllowed && !eventTypeId) { + log.warn({ message: "NewBooking: Some of the users in this group do not allow dynamic booking" }); throw new HttpError({ message: "Some of the users in this group do not allow dynamic booking", statusCode: 400, @@ -598,7 +616,10 @@ async function handler( }, ...userSelect, }); - if (!eventTypeUser) throw new HttpError({ statusCode: 404, message: "eventTypeUser.notFound" }); + if (!eventTypeUser) { + log.warn({ message: "NewBooking: eventTypeUser.notFound" }); + throw new HttpError({ statusCode: 404, message: "eventTypeUser.notFound" }); + } users.push(eventTypeUser); }