fix: return 404 when booking does not exist (#29583)

Signed-off-by: Chayan Das <daschayan8837@gmail.com>
Co-authored-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com>
This commit is contained in:
Chayan Das
2026-07-01 01:26:48 +05:30
committed by GitHub
co-authored by Bandhan Majumder
parent 5d6d4d30cc
commit 53e32a5bba
2 changed files with 28 additions and 1 deletions
@@ -49,6 +49,7 @@ import { getAllCredentialsIncludeServiceAccountKey } from "./getAllCredentialsFo
import { getBookingToDelete } from "./getBookingToDelete";
import cancelAttendeeSeat from "./handleSeats/cancel/cancelAttendeeSeat";
import type { IBookingCancelService } from "./interfaces/IBookingCancelService";
import { isPrismaError } from "@calcom/lib/server/getServerErrorFromUnknown";
const log = logger.getSubLogger({ prefix: ["handleCancelBooking"] });
@@ -102,7 +103,19 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
skipCancellationReasonValidation = false,
skipCalendarSyncTaskCancellation = false,
} = bookingCancelInput.parse(body);
const bookingToDelete = await getBookingToDelete(id, uid);
let bookingToDelete: BookingToDelete
try {
bookingToDelete = await getBookingToDelete(id, uid);
} catch (error) {
if (isPrismaError(error) && error.code === "P2025") // Record not found
{
throw new HttpError({
statusCode: 404,
message: "Booking not found.",
});
}
throw error;
}
const {
userId,
platformBookingUrl,
@@ -142,7 +142,21 @@ describe("Cancel Booking", () => {
},
},
});
});
test("Should throw when cancelling a non-existing booking", async () => {
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;
await expect(
handleCancelBooking({
bookingData: {
id: 99999,
uid: "non-existing-uid",
cancelledBy: "someone@example.com",
cancellationReason: "No reason",
},
})
).rejects.toThrow("Booking not found.");
});
test("Should call processPaymentRefund", async () => {