fix: add validation for empty hosts in round robin reassignment (#22429)
* fix: add validation for empty hosts in round robin reassignment - Add check for empty availableUsers array before calling getLuckyUser - Throw RoundRobinHostsUnavailableForBooking error instead of 500 error - Use existing error infrastructure with 409 status code and localized message - Prevents runtime errors when no round robin hosts are available for reassignment Co-Authored-By: [email protected] <[email protected]> * fix: check eventType.hosts.length directly for empty hosts validation - Move validation to check eventType.hosts.length === 0 immediately after hosts array setup - Remove later validation after ensureAvailableUsers to catch issue earlier - Follows user feedback to check hosts array directly instead of availableUsers Co-Authored-By: [email protected] <[email protected]> * fix: update translation message for round robin hosts unavailable error - Make error message clearer about event type having no hosts - Change from 'No Round Robin hosts is available for booking' to 'No hosts are available in this event type for round robin booking' Co-Authored-By: [email protected] <[email protected]> * Change error for event type no hosts * fix: add ErrorCode.EventTypeNoHosts to switch statement for 400 status code Addresses GitHub comment from keithwillcode to ensure EventTypeNoHosts error returns proper 400 Bad Request status instead of defaulting to 500. Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
4 files changed
+8
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
enrichHostsWithDelegationCredentials,
|
||||
enrichUserWithDelegationCredentialsIncludeServiceAccountKey,
|
||||
} from "@calcom/lib/delegationCredential/server";
|
||||
import { ErrorCode } from "@calcom/lib/errorCodes";
|
||||
import { getEventName } from "@calcom/lib/event";
|
||||
import { IdempotencyKeyService } from "@calcom/lib/idempotencyKey/idempotencyKeyService";
|
||||
import { isPrismaObjOrUndefined } from "@calcom/lib/isPrismaObj";
|
||||
@@ -99,6 +100,10 @@ export const roundRobinReassignment = async ({
|
||||
createdAt: new Date(0), // use earliest possible date as fallback
|
||||
}));
|
||||
|
||||
if (eventType.hosts.length === 0) {
|
||||
throw new Error(ErrorCode.EventTypeNoHosts);
|
||||
}
|
||||
|
||||
const roundRobinHosts = eventType.hosts.filter((host) => !host.isFixed);
|
||||
|
||||
const originalOrganizer = booking.user;
|
||||
|
||||
Reference in new issue
Block a user