fix: api v2 booking controller handle error codes (#16486)
* fix: api v2 booking controller handle error codes * fixup! fix: api v2 booking controller handle error codes * fixup! Merge branch 'main' into fix-booking-controller-errors-api-v2
This commit is contained in:
1 parent
26be88fc56
commit
31bfa9e32e
4 files changed
+53
-4
No files matched your search
@@ -26,7 +26,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@calcom/platform-constants": "*",
|
"@calcom/platform-constants": "*",
|
||||||
"@calcom/platform-enums": "*",
|
"@calcom/platform-enums": "*",
|
||||||
"@calcom/platform-libraries": "npm:@calcom/[email protected]1",
|
"@calcom/platform-libraries": "npm:@calcom/[email protected]3",
|
||||||
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
|
||||||
"@calcom/platform-types": "*",
|
"@calcom/platform-types": "*",
|
||||||
"@calcom/platform-utils": "*",
|
"@calcom/platform-utils": "*",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { withApiAuth } from "test/utils/withApiAuth";
|
|||||||
|
|
||||||
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
|
||||||
import { handleNewBooking } from "@calcom/platform-libraries";
|
import { handleNewBooking } from "@calcom/platform-libraries";
|
||||||
import { ApiSuccessResponse, ApiResponse } from "@calcom/platform-types";
|
import { ApiSuccessResponse, ApiResponse, ApiErrorResponse } from "@calcom/platform-types";
|
||||||
|
|
||||||
describe("Bookings Endpoints", () => {
|
describe("Bookings Endpoints", () => {
|
||||||
describe("User Authenticated", () => {
|
describe("User Authenticated", () => {
|
||||||
@@ -144,6 +144,49 @@ describe("Bookings Endpoints", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should fail to create a booking with no_available_users_found_error", async () => {
|
||||||
|
const bookingStart = "2040-05-21T09:30:00.000Z";
|
||||||
|
const bookingEnd = "2040-05-21T10:30:00.000Z";
|
||||||
|
const bookingEventTypeId = eventTypeId;
|
||||||
|
const bookingTimeZone = "Europe/London";
|
||||||
|
const bookingLanguage = "en";
|
||||||
|
const bookingHashedLink = "";
|
||||||
|
const bookingMetadata = {
|
||||||
|
timeFormat: "12",
|
||||||
|
meetingType: "organizer-phone",
|
||||||
|
};
|
||||||
|
const bookingResponses = {
|
||||||
|
name: "tester",
|
||||||
|
email: "[email protected]",
|
||||||
|
location: {
|
||||||
|
value: "link",
|
||||||
|
optionValue: "",
|
||||||
|
},
|
||||||
|
notes: "test",
|
||||||
|
guests: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const body: CreateBookingInput = {
|
||||||
|
start: bookingStart,
|
||||||
|
end: bookingEnd,
|
||||||
|
eventTypeId: bookingEventTypeId,
|
||||||
|
timeZone: bookingTimeZone,
|
||||||
|
language: bookingLanguage,
|
||||||
|
metadata: bookingMetadata,
|
||||||
|
hashedLink: bookingHashedLink,
|
||||||
|
responses: bookingResponses,
|
||||||
|
};
|
||||||
|
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.post("/v2/bookings")
|
||||||
|
.send(body)
|
||||||
|
.expect(400)
|
||||||
|
.then(async (response) => {
|
||||||
|
const responseBody: ApiErrorResponse = response.body;
|
||||||
|
expect(responseBody.error.message).toEqual("no_available_users_found_error");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should create a booking with api key to get owner id", async () => {
|
it("should create a booking with api key to get owner id", async () => {
|
||||||
const bookingStart = "2040-05-22T09:30:00.000Z";
|
const bookingStart = "2040-05-22T09:30:00.000Z";
|
||||||
const bookingEnd = "2040-05-22T10:30:00.000Z";
|
const bookingEnd = "2040-05-22T10:30:00.000Z";
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import {
|
|||||||
getBookingInfo,
|
getBookingInfo,
|
||||||
handleCancelBooking,
|
handleCancelBooking,
|
||||||
getBookingForReschedule,
|
getBookingForReschedule,
|
||||||
|
ErrorCode,
|
||||||
} from "@calcom/platform-libraries";
|
} from "@calcom/platform-libraries";
|
||||||
import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types";
|
import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types";
|
||||||
import { ApiResponse } from "@calcom/platform-types";
|
import { ApiResponse } from "@calcom/platform-types";
|
||||||
@@ -366,6 +367,9 @@ export class BookingsController {
|
|||||||
|
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
const error = err as Error;
|
const error = err as Error;
|
||||||
|
if (Object.values(ErrorCode).includes(error.message as unknown as ErrorCode)) {
|
||||||
|
throw new HttpException(error.message, 400);
|
||||||
|
}
|
||||||
throw new InternalServerErrorException(error?.message ?? errMsg);
|
throw new InternalServerErrorException(error?.message ?? errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
|
|||||||
import handleMarkNoShow from "@calcom/features/handleMarkNoShow";
|
import handleMarkNoShow from "@calcom/features/handleMarkNoShow";
|
||||||
import * as instantMeetingMethods from "@calcom/features/instant-meeting/handleInstantMeeting";
|
import * as instantMeetingMethods from "@calcom/features/instant-meeting/handleInstantMeeting";
|
||||||
import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings";
|
import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings";
|
||||||
import { symmetricEncrypt } from "@calcom/lib/crypto";
|
import { symmetricEncrypt, symmetricDecrypt } from "@calcom/lib/crypto";
|
||||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||||
import { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler";
|
import { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler";
|
||||||
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
|
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
|
||||||
@@ -112,7 +112,7 @@ export type { SystemField, UserField } from "@calcom/lib/event-types/transformer
|
|||||||
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||||
export { dynamicEvent } from "@calcom/lib/defaultEvents";
|
export { dynamicEvent } from "@calcom/lib/defaultEvents";
|
||||||
|
|
||||||
export { symmetricEncrypt };
|
export { symmetricEncrypt, symmetricDecrypt };
|
||||||
export { CalendarService };
|
export { CalendarService };
|
||||||
|
|
||||||
export { getCalendar };
|
export { getCalendar };
|
||||||
@@ -120,3 +120,5 @@ export { getCalendar };
|
|||||||
export { getTranslation };
|
export { getTranslation };
|
||||||
|
|
||||||
export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";
|
||||||
|
|
||||||
|
export { ErrorCode } from "@calcom/lib/errorCodes";
|
||||||
Reference in new issue
Block a user