fix: eventtype null cant be booked error (#18975)

* fix err msg and add more description

* improvements

* fix cause

* add warn logs for when failing to specific limit checks

* typefix

* safestringify log

* improve error

* test fix and log min booking notice

* adds out of bounds error code

* test fix

* fix
This commit is contained in:
Syed Ali Shahbaz authored and GitHub committed 2025-01-29 13:00:51 +00:00
1 parent 8615ccb1aa
commit 92678dc042
5 files changed
+64 -31

No files matched your search

@@ -772,7 +772,9 @@ describe("handleNewBooking", () => {
mockCalendarToHaveNoBusySlots("googlecalendar", {});
await createBookingScenario(scenarioData);
await expect(() => handleNewBooking(req)).rejects.toThrowError("book a meeting in the past");
await expect(() => handleNewBooking(req)).rejects.toThrowError(
"Attempting to book a meeting in the past."
);
},
timeout
);
@@ -865,7 +867,7 @@ describe("handleNewBooking", () => {
},
});
expect(() => handleNewBooking(req)).rejects.toThrowError("cannot be booked at this time");
expect(() => handleNewBooking(req)).rejects.toThrowError("booking_time_out_of_bounds_error");
},
timeout
);
@@ -1,6 +1,7 @@
import type { Logger } from "tslog";
import { getUTCOffsetByTimezone } from "@calcom/lib/date-fns";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { HttpError } from "@calcom/lib/http-error";
import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds";
import type { EventType } from "@calcom/prisma/client";
@@ -15,6 +16,7 @@ type ValidateBookingTimeEventType = Pick<
| "minimumBookingNotice"
| "eventName"
| "id"
| "title"
>;
export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBookingTimeEventType>(
@@ -41,22 +43,14 @@ export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBook
);
} catch (error) {
logger.warn({
message: "NewBooking: Unable set timeOutOfBounds. Using false. ",
message: "NewBooking: Unable to determine timeOutOfBounds status. Defaulting to false.",
});
if (error instanceof BookingDateInPastError) {
logger.info(`Booking eventType ${eventType.id} failed`, JSON.stringify({ error }));
throw new HttpError({ statusCode: 400, message: error.message });
}
}
if (timeOutOfBounds) {
const error = {
errorCode: "BookingTimeOutOfBounds",
message: `EventType '${eventType.eventName}' cannot be booked at this time.`,
};
logger.warn({
message: `NewBooking: EventType '${eventType.eventName}' cannot be booked at this time.`,
});
throw new HttpError({ statusCode: 400, message: error.message });
}
if (timeOutOfBounds) throw new Error(ErrorCode.BookingTimeOutOfBounds);
};