Skip to content

fix: not found handling for bookings and Prisma record lookups#29583

Draft
ChayanDass wants to merge 1 commit into
calcom:mainfrom
ChayanDass:fix/booking-not-found-errors
Draft

fix: not found handling for bookings and Prisma record lookups#29583
ChayanDass wants to merge 1 commit into
calcom:mainfrom
ChayanDass:fix/booking-not-found-errors

Conversation

@ChayanDass

@ChayanDass ChayanDass commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #28614

This PR improves handling of not-found scenarios by returning proper HTTP 404 responses instead of exposing Prisma errors to API consumers.

Changes

Booking deletion/cancellation

getBookingToDelete() previously used prisma.booking.findUniqueOrThrow(), which could surface an unhandled Prisma error when a booking did not exist.

This has been replaced with findUnique() and an explicit null check.

Before:

  • Prisma NotFoundError could propagate to clients
  • Missing bookings could appear as server errors

After:

  • Missing bookings return HTTP 404
  • Clear and user-friendly error messages are returned

Example:

{
  "message": "Booking does not exist"
}

Visual Demo

Before

image

After

image

Mandatory Tasks

  • I have self-reviewed the code.
  • I have updated the developer docs if this PR makes changes that would require a documentation change. N/A.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Setup

Run Cal.diy locally with a valid development environment and database.

Reproduction

  1. Create a booking and verify cancellation still works.
  2. Send a cancellation request using a non-existent booking UID.
  3. Trigger a Prisma P2025 or P2001 error path.

Expected Results

Existing booking

Returns a successful cancellation response.

Missing booking

Returns HTTP 404:

{
  "message": "Booking with uid non-existent-uid-12345 does not exist"
}

Prisma not-found errors

Return HTTP 404:

{
  "message": "The requested record was not found."
}

No Prisma stack traces or internal error details should be exposed.

Checklist

  • I have read the contributing guide.
  • My code follows the style guidelines of this project.
  • I have commented code where necessary.
  • I have checked that my changes generate no new warnings.
  • This PR is appropriately scoped.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @ChayanDass! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Fix not found handling for bookings and Prisma record lookups". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

getBookingToDelete switches from prisma.booking.findUniqueOrThrow to findUnique, adds an HttpError import, and throws an HttpError with statusCode: 404 when the result is null, including a message built from whichever of id or uid was supplied. Separately, getServerErrorFromPrismaError introduces a NOT_FOUND_CODES array containing P2025 and P2001; when a Prisma KnownRequestError matches either code, it now returns an HttpError(404) with the message "The requested record was not found." instead of routing through the generic getHttpError mapping.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully addresses issue #28614 by replacing findUniqueOrThrow with findUnique and explicit null checks, returning HTTP 404 with user-friendly messages instead of exposing Prisma errors.
Out of Scope Changes check ✅ Passed All changes are directly in scope: getBookingToDelete and getServerErrorFromPrismaError modifications address the linked issue requirements without introducing unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately captures the main changes: fixing not found error handling for both bookings and Prisma record lookups, returning proper 404 responses instead of exposing internal Prisma errors.
Description check ✅ Passed The PR description clearly explains the changes: replacing findUniqueOrThrow with findUnique and explicit null checks in getBookingToDelete(), updating Prisma error handling for P2025/P2001 codes, and includes before/after screenshots demonstrating the improvement from exposing Prisma errors to returning clean HTTP 404 responses.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ChayanDass ChayanDass force-pushed the fix/booking-not-found-errors branch 3 times, most recently from 43abd88 to e870ac8 Compare June 15, 2026 20:39
@ChayanDass ChayanDass changed the title Fix not found handling for bookings and Prisma record lookups fix: not found handling for bookings and Prisma record lookups Jun 15, 2026
@ChayanDass

Copy link
Copy Markdown
Contributor Author

@bandhan-majumder , Please take a look whenever you are free!

Comment thread packages/features/bookings/lib/getBookingToDelete.ts Outdated
Comment thread packages/lib/server/getServerErrorFromUnknown.ts

@bandhan-majumder bandhan-majumder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments and since this PR (#28614) is inactive, I would rather focus on the current one. Also please take care of this comment: #28621 (review) if u have not already!! Also can u add some test cases so the fix can be verified??

@bandhan-majumder bandhan-majumder marked this pull request as draft June 16, 2026 07:54
@bandhan-majumder bandhan-majumder self-assigned this Jun 16, 2026
@ChayanDass ChayanDass force-pushed the fix/booking-not-found-errors branch from e870ac8 to 397ffca Compare June 16, 2026 10:25
@pull-request-size pull-request-size Bot added size/L and removed size/S labels Jun 16, 2026
@ChayanDass

Copy link
Copy Markdown
Contributor Author

@bandhan-majumder , Ready for review, please check!

@CLAassistant

CLAassistant commented Jun 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bandhan-majumder

Copy link
Copy Markdown
Member

left some comments and since this PR (#28614) is inactive, I would rather focus on the current one. Also please take care of this comment: #28621 (review) if u have not already!! Also can u add some test cases so the fix can be verified??

this fix is correct but it has to be handled in the trpc handler. This comment I mentioned here, suggests that only. The first PR which was opened claiming to fix this issue, go through the conversation. It also has the same fix on the prisma level but not on the trpc level. Hope that helps!

Signed-off-by: Chayan Das <daschayan8837@gmail.com>
@ChayanDass ChayanDass force-pushed the fix/booking-not-found-errors branch from 397ffca to ce4fe19 Compare June 18, 2026 10:50
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: /api/cancel returns raw Prisma error for non-existent booking UID

3 participants