calcom/cal.diy · error · HttpException

error.message

Error message

error.message

What it means

This is the message expression inside handleBookingErrors when the caught error is a plain Error whose message property exactly matches one of the ErrorCode enum values (e.g., 'booking_conflict_error', 'booking_not_found_error', 'event_type_not_found_error', 'booking_seats_full_error'). The handler maps these domain error codes to a 400 Bad Request HttpException.

Source

Thrown at apps/api/v2/src/platform/bookings/2024-04-15/controllers/bookings.controller.ts:602

    err: Error | HttpError | unknown,
    type?: "recurring" | `instant` | "no-show"
  ): void {
    const errMsg =
      type === "no-show"
        ? `Error while marking no-show.`
        : `Error while creating ${type ? `${type} ` : ""}booking.`;
    if (err instanceof HttpError) {
      const httpError = err as HttpError;
      throw new HttpException(httpError?.message ?? errMsg, httpError?.statusCode ?? 500);
    }

    if (err instanceof Error) {
      const error = err as Error;
      if (err instanceof HttpException) {
        throw new HttpException(err.getResponse(), err.getStatus());
      }
      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(errMsg);
  }

  private transformToBoolean(v?: string): boolean {
    return v && typeof v === "string" ? v.toLowerCase() === "true" : false;
  }
}

View on GitHub (pinned to 176037d0af)

Solutions

  1. Map the ErrorCode string in the response to the specific domain problem — see packages/lib/errorCodes.ts for the full list of 40+ codes.
  2. For booking_conflict_error: pick a different time slot and retry.
  3. For not_enough_available_seats_error / booking_seats_full_error: reduce the number of seats requested or choose a different event type with more capacity.
  4. For booking_time_out_of_bounds_error: check the event type's minimumBookingNotice and schedulingWindow settings and pick a time within range.
  5. For booker_limit_exceeded_error: wait until the limit resets or contact the organizer.
Defensive patterns

Strategy: try-catch

Type guard

// Identify known ErrorCode values in the response
import { ErrorCode } from '@calcom/platform-libraries/errors';

function isKnownErrorCode(message) {
  return Object.values(ErrorCode).includes(message);
}

// Usage: if (isKnownErrorCode(err.message)) { /* handle domain error */ }

Try / catch

try {
  await api.createBooking(payload);
} catch (err) {
  if (err.statusCode === 400 && isKnownErrorCode(err.message)) {
    switch (err.message) {
      case 'booking_conflict_error': handleSlotConflict(); break;
      case 'not_enough_available_seats_error': handleSeatsFull(); break;
      case 'booking_time_out_of_bounds_error': handleTimeWindow(); break;
      default: handleOtherDomainError(err.message);
    }
  } else { throw err; }
}

Prevention

When it happens

Trigger: The booking service or a downstream repository throws a plain Error with a message set to an ErrorCode string. This pattern is used when the service layer wants to signal a known domain error without coupling to NestJS exception classes. Examples: Error('booking_conflict_error'), Error('not_enough_available_seats_error'), Error('booking_time_out_of_bounds_error').

Common situations: Double-booking a time slot (booking_conflict_error), booking a seated event type that's full (booking_seats_full_error / not_enough_available_seats_error), requesting a time outside the allowed booking window (booking_time_out_of_bounds_error), referencing a deleted event type (event_type_not_found_error), or exceeding the booker's booking limit (booker_limit_exceeded_error).

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/55228077cabfa25a. Report an issue: GitHub.