Skip to content

Commit

Permalink
fix: api v2 booking controller handle error codes (#16486)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ThyMinimalDev authored and zomars committed Sep 4, 2024
1 parent 2ada394 commit 91813b9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/api/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.31",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.33",
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { withApiAuth } from "test/utils/withApiAuth";

import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
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("User Authenticated", () => {
Expand Down Expand Up @@ -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: "tester@example.com",
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 () => {
const bookingStart = "2040-05-22T09:30:00.000Z";
const bookingEnd = "2040-05-22T10:30:00.000Z";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
getBookingInfo,
handleCancelBooking,
getBookingForReschedule,
ErrorCode,
} from "@calcom/platform-libraries";
import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types";
import { ApiResponse } from "@calcom/platform-types";
Expand Down Expand Up @@ -366,6 +367,9 @@ export class BookingsController {

if (err instanceof 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);
}

Expand Down
6 changes: 4 additions & 2 deletions packages/platform/libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent";
import handleMarkNoShow from "@calcom/features/handleMarkNoShow";
import * as instantMeetingMethods from "@calcom/features/instant-meeting/handleInstantMeeting";
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 { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler";
import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util";
Expand Down Expand Up @@ -112,11 +112,13 @@ export type { SystemField, UserField } from "@calcom/lib/event-types/transformer
export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
export { dynamicEvent } from "@calcom/lib/defaultEvents";

export { symmetricEncrypt };
export { symmetricEncrypt, symmetricDecrypt };
export { CalendarService };

export { getCalendar };

export { getTranslation };

export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries";

export { ErrorCode } from "@calcom/lib/errorCodes";

0 comments on commit 91813b9

Please sign in to comment.