Skip to content

Scheduling infrastructure for absolutely everyone.

fix: API booking issues (#15247)

Keith Williams5f082e11f8c8
diff --git a/apps/api/v1/lib/validations/booking.ts b/apps/api/v1/lib/validations/booking.ts
index 65f73fe8de9..e9dda7865be 100644
--- a/apps/api/v1/lib/validations/booking.ts
+++ b/apps/api/v1/lib/validations/booking.ts
@@ -55,7 +55,7 @@ export const schemaBookingReadPublic = Booking.extend({
timeZone: true,
locale: true,
})
- .optional(),
+ .nullish(),
payment: z
.array(
_PaymentModel.pick({
diff --git a/apps/api/v1/pages/api/bookings/_post.ts b/apps/api/v1/pages/api/bookings/_post.ts
index 9fe55b773a4..919a7a2bfc5 100644
--- a/apps/api/v1/pages/api/bookings/_post.ts
+++ b/apps/api/v1/pages/api/bookings/_post.ts
@@ -2,6 +2,8 @@ import type { NextApiRequest } from "next";
import getBookingDataSchemaForApi from "@calcom/features/bookings/lib/getBookingDataSchemaForApi";
import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";
+import { ErrorCode } from "@calcom/lib/errorCodes";
+import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server";
import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
@@ -218,7 +220,16 @@ async function handler(req: NextApiRequest) {
req.userId = requestedUserId || userId;
}
- return await handleNewBooking(req, getBookingDataSchemaForApi);
+ try {
+ return await handleNewBooking(req, getBookingDataSchemaForApi);
+ } catch (error: unknown) {
+ const knownError = error as Error;
+ if (knownError?.message === ErrorCode.NoAvailableUsersFound) {
+ throw new HttpError({ statusCode: 400, message: knownError.message });
+ }
+
+ throw error;
+ }
}
export default defaultResponder(handler);